What causes the following error?
===== Image 'rect.tikz' is up-to-date. ====== ./rect.tikz:3: error: (file rect.tikz) (pdf backend): internal error: unknown image type ./rect.tikz:3: ==> Fatal error occurred, no output PDF file produced!
\documentclass[
addpoints,
]{exam}
\begin{filecontents}[overwrite]{rect.tikz}
\begin{tikzpicture}[x=1em, y=1em,blue]
\draw (0,0) rectangle node{Diaa} (4,4);
\end{tikzpicture}
\end{filecontents}
\usepackage{catchfile,lipsum,graphbox,array,ragged2e,booktabs,fmtcount,multicol,multirow,calc,tikz,calc,mathtools,tikzscale,lua-ul,enumitem,xfrac,siunitx,comment,matlab-prettifier,atveryend,pdfpages,afterpage,lastpage,longtable,pgfmath,xfp,ifthen}
% 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
\newcommand{\inputtikz}[1]{%
\tikzset{external/export=true}%
\tikzsetnextfilename{#1}%
\input{#1}%
\tikzset{external/export=false}%
}
\usepackage[xparse,breakable,raster,skins]{tcolorbox}% xparse,breakable
\tcbset{shield externalize}
\tcbuselibrary{fitting}
\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}
\end{document}
rect.tikz, call it, say,myrectand add a second parameter to your macro.rect.tikzis the name of the text file containing the code for the tikz picture. Name the PDF with\tikzsetnextfilename{#2}(if you make the PDF name the second parameter. Then your macro call becomes\inputtikz{rect.tikz}{myrect}. – Cicada Dec 23 '20 at 07:51\NewDocumentCommand{\inputtikz}{ m m }{% \tikzset{external/export=true}% \tikzsetnextfilename{#2}% \input{#1}% \tikzset{external/export=false}% }with\inputtikz{{"the rect"}.tikz}{{"my rect"}}? – Diaa Dec 23 '20 at 08:23\inputtikz{"b rect.tikz"}{myrect}works for me (Windows). Ask a separate question to get a proper answer for your setup. No-one will look undererrorstikz-externalfor a space-in-filename question buried in the comments. – Cicada Dec 23 '20 at 10:11