tikz add tag
Diaa (imported from SE)
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}
```
Top Answer
Diaa
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.

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.