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.


    \begin{tikzpicture}[x=1em, y=1em,blue]
        \draw (0,0) rectangle node{Diaa} (4,4);




% https://topanswers.xyz/tex?q=1562#a1814
    \immediate\write\@mainaux{\string\expandafter\xdef\noexpand\csname pgfk@/tikz/external/watch/stored/#1\string\endcsname{#2}}}%
    \ifcsname pgfk@/tikz/external/watch/stored/#1\endcsname
    \edef#2{\csname pgfk@/tikz/external/watch/stored/#1\endcsname}%
\tikzset{external/watch/.cd,store/.code 2 args={%
    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}}%
        \tikzset{/tikz/external/force remake}%

% 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 }{%
    }{% https://tex.stackexchange.com/a/383190/2288
        \typeout{Error: Missing file: #1}

\usetikzlibrary{arrows, shapes, calc, positioning, patterns, decorations, decorations.markings, quotes, fpu, patterns, decorations.pathmorphing}

% for DC Motor Circuit Drawing
        \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}



% https://topanswers.xyz/transcript?room=1605&id=85129#c85129
    watch/font size, 
    export = false,


  • You are loading in your example more than 40 packages, and most of them are probably unrelated. Dec 23, 2020 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, 2020 at 14:15
  • @UlrikeFischer Please, check my updated version.
    – Diaa
    Dec 23, 2020 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) Dec 23, 2020 at 14:42
  • 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. Dec 23, 2020 at 15:08

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .