1

Why do I get this error of missing \begin{document} in the log file therect.log of the externally built image threct.pdf?

P.S. I am sorry for not fully cleaning the code of repeated package loading and unnecessary packages.


\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}

Diaa
  • 9,599
  • You are loading in your example more than 40 packages, and most of them are probably unrelated. – Ulrike Fischer Dec 23 '20 at 13:55
  • @UlrikeFischer When I reduced my document before, I couldn't manage to get the error reproduced. So, I started with this messy version hoping to reduce it properly without losing the error. – Diaa Dec 23 '20 at 14:15
  • @UlrikeFischer Please, check my updated version. – Diaa Dec 23 '20 at 14:24
  • sorry it is not reasonable to post that much obscure code and ask people to run with --shell-escape shell escape is disabled for a reason. (that said if someone does trust you enough to run the posted example, it runs without error) – David Carlisle Dec 23 '20 at 14:42
  • @DavidCarlisle No problem. I will delete the whole question. – Diaa Dec 23 '20 at 14:44
  • you (again!!) have not provided the log showing the error that you got. I get no error from this example. – David Carlisle Dec 23 '20 at 14:45
  • @DavidCarlisle I am not sparing the log . I just showed the error. Anyway, here it is that of therect https://pastebin.com/Zz1BXHJ2 which has the missing begin{document}. And this is of the main file https://pastebin.com/wVAWb6Cu – Diaa Dec 23 '20 at 14:48
  • why use external links? The question is archived forever and your pastebin links are probably not. – David Carlisle Dec 23 '20 at 14:50
  • @DavidCarlisle I don't prefer making the question that long. Anyway, I will put them in the question itself. – Diaa Dec 23 '20 at 14:51
  • @DavidCarlisle I found out the problem and don't know if I should delete the question or keep it. The main cause was having a space in the main file, and I know how much you hate spaces XD. However, is there any clue in the log file leads me to true the criminal? – Diaa Dec 23 '20 at 14:54
  • I was just coming back to post https://chat.stackexchange.com/transcript/message/13311129#13311129 as I saw the space in your log, once I saw your comment above – David Carlisle Dec 23 '20 at 14:56
  • let me see if I can reproduce with a space, although it may be windows specific – David Carlisle Dec 23 '20 at 14:57
  • OK I can reproduce if there is a space in the filename, error not clear from the log but as I comment above just seeing the filename in your log would be enough for me to suggest the fix of not having a space. – David Carlisle Dec 23 '20 at 15:00
  • @DavidCarlisle The space here was accidental not intentional, and if you are not such texpert, you take a lot of time like me. Please, advise, should I delete, close, answer the question? – Diaa Dec 23 '20 at 15:03
  • 2
    actually I think it is worth answering as I have to admit the error message here is completely impossible to understand the guess of trying it without a space in the name comes from experience not anything in the log. Others may be helped to see that, you could self answer. – David Carlisle Dec 23 '20 at 15:08

1 Answers1

3

This error is a result of having a space in the file name of the main document.

Furthermore, when dealing with the external library of tikz spaces are so notorious and explosive (when used in the names of main file,\tikzsetnextfilename, *.tikz file) and give completely incomprehensible errors as the one in my question.

Diaa
  • 9,599