![TikZ/external:LaTeX 错误:缺少 \begin{document}](https://linux22.com/image/426003/TikZ%2Fexternal%EF%BC%9ALaTeX%20%E9%94%99%E8%AF%AF%EF%BC%9A%E7%BC%BA%E5%B0%91%20%5Cbegin%7Bdocument%7D.png)
为什么我在外部构建的图像的missing \begin{document}
日志文件中出现此错误?therect.log
threct.pdf
PS:很抱歉没有完全清理重复的包加载和不必要的包的代码。
\PassOptionsToPackage{table}{xcolor}
\PassOptionsToPackage{export}{adjustbox}
\begin{filecontents*}[overwrite]{rect.tikz}
\begin{tikzpicture}[x=1em, y=1em,blue]
\draw (0,0) rectangle node{Diaa} (4,4);
\end{tikzpicture}
\end{filecontents*}
\documentclass[
addpoints,
%answers
]{exam}
\usepackage{catchfile,lipsum,graphbox,array,ragged2e,booktabs,fmtcount,multicol,multirow,calc,tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% https://topanswers.xyz/tex?q=1562#a1814
\makeatletter
\def\tikz@external@watch@store@aux#1#2{%
\immediate\write\@mainaux{\string\expandafter\xdef\noexpand\csname pgfk@/tikz/external/watch/stored/#1\string\endcsname{#2}}}%
\def\tikz@external@watch@get@from@aux#1#2{%
\ifcsname pgfk@/tikz/external/watch/stored/#1\endcsname
\edef#2{\csname pgfk@/tikz/external/watch/stored/#1\endcsname}%
\else
\edef#2{0}%
\fi}
\tikzset{external/watch/.cd,store/.code 2 args={%
\tikz@external@watch@store@aux{#1}{#2}},
get/.code 2 args={\tikz@external@watch@get@from@aux{#1}{#2}},
font size/.code={\tikzset{external/watch/get={font size}{\pgfutil@tempa},
external/watch/store={font size}{\f@size}}%
\unless\ifnum\pgfutil@tempa=\f@size
\tikzset{/tikz/external/force remake}%
\fi
}}
\makeatother
\usetikzlibrary{external}
% https://tex.stackexchange.com/a/482560/2288
% https://topanswers.xyz/transcript?room=1605&id=85129#c85129
% https://tex.stackexchange.com/q/576077/2288
\NewDocumentCommand{\inputtikz}{ m m }{%
\IfFileExists{#1}{%
\tikzset{external/export=true}%
\tikzsetnextfilename{#2}%
\input{#1}%
\tikzset{external/export=false}%
}{% https://tex.stackexchange.com/a/383190/2288
\typeout{Error: Missing file: #1}
\ExitDueToUndefinedControlSequence%
}%
}
\usepackage[american,siunitx]{circuitikz}
\usetikzlibrary{arrows, shapes, calc, positioning, patterns, decorations, decorations.markings, quotes, fpu, patterns, decorations.pathmorphing}
% for DC Motor Circuit Drawing
\tikzset{rotarrow/.pic={
\draw[thin,->] (-0.2,-0.2) to [out=-60,in=60, looseness=4] ++(0,0.4) node [above=1mm] {\tikzpictext};
},
}
\usepackage[xparse,breakable,raster,skins]{tcolorbox}% xparse,breakable
\tcbset{shield externalize}
\tcbuselibrary{fitting}
%https://tex.stackexchange.com/a/331068/2288
\newcommand\blankpage{%
\clearpage
\begingroup
\null
\thispagestyle{empty}%
\addtocounter{page}{-1}%
\hypersetup{pageanchor=false}%
\clearpage
\endgroup
}
\setlength{\parindent}{0cm}
\tikzexternalize
\begin{document}
% https://topanswers.xyz/transcript?room=1605&id=85129#c85129
\tikzset{external/.cd,
watch/font size,
export = false,
}
\inputtikz{rect.tikz}{therect}
\end{document}
答案1
此错误是由于主文档的文件名中有空格而导致的。
此外,在处理外部库时,空格是如此臭名昭著和具有爆炸性(当用于、、文件tikz
的名称时),并且会出现完全无法理解的错误,就像我的问题中的那样。main file
\tikzsetnextfilename
*.tikz