# TikZ: How to pass the font size of the calling document to the called standalone tikz file?

I would like to make any change in the font size of the main calling document affect the font size of the text and the drawing dimensions of the standalone file since any current change in the article font size has no effect on the standalone file.

The following images shows no change in the text font size of the standalone tikz drawing despite changing it in the calling document.

\begin{filecontents*}{pic.tex}
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[x=1em, y=1em, font=\normalsize]
\draw (0,0) rectangle node{Test} (2,2);
\end{tikzpicture}
\end{document}
\end{filecontents*}

\documentclass{article}
\usepackage[fontsize=14pt]{scrextend}
\usepackage[mode=build, subpreambles=false]{standalone}
\begin{document}
fontsize = 14pt
\includestandalone{pic}
\end{document}


## Update 1 (Compiling case (d) of @Cicada's answer)

\begin{filecontents*}{pic\jobname.tex}
\documentclass{standalone}
\usetikzlibrary{shapes}
\begin{document}
\color{red}
inside
\begin{tikzpicture}[x=1em, y=1em]
\draw (0,0) rectangle node{Test} (2,2);
\end{tikzpicture}
\end{document}
\end{filecontents*}

\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage[fontsize=14pt]{scrextend}
\usepackage[mode=build, subpreambles=false]{standalone}
\begin{document}
\section*{d}
fontsize = 14pt \includestandalone{pic\jobname}

\huge fontsize huge \includestandalone{pic\jobname}

\tiny fontsize tiny \includestandalone{pic\jobname}
\end{document}


### Output

4 almost empty pages

https://docdro.id/4t5urCy

### log file of main document

https://pastebin.com/ws9Fj0tA

### log file of standalone file

https://pastebin.com/Dt7phZrU

• LaTeX Warning: Unused global option(s): [32pt] - valid sizes are 8,10, 12, I think. You may need to use relative-size commands like \huge, or fontspec's Scale= option. – Cicada Dec 13 '20 at 9:39
• @Cicada Please, check my question update. – Diaa Dec 13 '20 at 15:23
• Is font=\normalsize in the include intentional? – Cicada Dec 14 '20 at 8:19
• filecontents needs the [overwrite] option, if experimenting. – Cicada Dec 14 '20 at 9:03
• "any settings done in the main document which would affects the source code will not have an effect on the image. This can be positive or negative dependent on the case." - p26 of the manual. – Cicada Dec 19 '20 at 1:58

## 1 Answer

Not an answer because the question as far as I can understand it relates to the standalone image(PDF) to be included in the main file, with the proviso that the standalone PDF be compiled only once to save compilation time.

If, instead, standalone source code is used, the standalone PDF will inherit any applicable main document settings like fontsize but the standalone PDF will be (re)compiled on each run of the main document.

If source code is used:

(Original answer)

Don't use font=\normalsize inside your tikz picture.

(a) Your question code does not load tikz at the correct time: "Environment tikzpicture undefined.", says the log. tikz package needs to be loaded before tikz commands can be used.

No illustration (a).

(b) \begin{tikzpicture}[x=1em, y=1em, font=\normalsize] sets the fontsize inside the rectangle, overriding the font size used in and by the calling file at that point in the processing. The rectangle size is set to relative font size (em) so expands or contracts with it.

MWE

\begin{filecontents*}{pic\jobname.tex}
\documentclass{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[x=1em, y=1em, font=\normalsize]
\draw (0,0) rectangle node{Test} (2,2);
\end{tikzpicture}
\end{document}
\end{filecontents*}

\documentclass{article}
\usepackage{tikz}
\usepackage[fontsize=14pt]{scrextend}
\usepackage[mode=build, subpreambles=false]{standalone}
\begin{document}
\section*{b}
fontsize = 14pt \includestandalone{pic\jobname}

\huge fontsize huge \includestandalone{pic\jobname}

\tiny fontsize tiny \includestandalone{pic\jobname}
\end{document}


(c) Do \begin{tikzpicture}[x=1em, y=1em] so as not to override the font size.

MWE

\begin{filecontents*}{pic\jobname.tex}
\documentclass{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[x=1em, y=1em]
\draw (0,0) rectangle node{Test} (2,2);
\end{tikzpicture}
\end{document}
\end{filecontents*}

\documentclass{article}
\usepackage{tikz}
\usepackage[fontsize=14pt]{scrextend}
\usepackage[mode=build, subpreambles=false]{standalone}
\begin{document}
\section*{c}
fontsize = 14pt \includestandalone{pic\jobname}

\huge fontsize huge \includestandalone{pic\jobname}

\tiny fontsize tiny \includestandalone{pic\jobname}
\end{document}


(d) Notice that inside the included file, formatting commands (e.g., colour) are restricted to the file itself. This implies that the contents of the included file are processed in their own group (as if with {...} or equivalents).

MWE

\begin{filecontents*}{pic\jobname.tex}
\documentclass{standalone}
\usetikzlibrary{shapes}
\begin{document}
\color{red}
inside
\begin{tikzpicture}[x=1em, y=1em]
\draw (0,0) rectangle node{Test} (2,2);
\end{tikzpicture}
\end{document}
\end{filecontents*}

\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage[fontsize=14pt]{scrextend}
\usepackage[mode=build, subpreambles=false]{standalone}
\begin{document}
\section*{d}
fontsize = 14pt \includestandalone{pic\jobname}

\huge fontsize huge \includestandalone{pic\jobname}

\tiny fontsize tiny \includestandalone{pic\jobname}
\end{document}


(e) Fontsize option for the documentclass works as expected.

MWE

\begin{filecontents*}{pic\jobname.tex}
\documentclass{standalone}
\usetikzlibrary{shapes}
\begin{document}
\color{red}
inside
\begin{tikzpicture}[x=1em, y=1em]
\draw (0,0) rectangle node{Test} (2,2);
\end{tikzpicture}
\end{document}
\end{filecontents*}

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{scrextend}
\usepackage[mode=build, subpreambles=false]{standalone}
\begin{document}
\section*{e}
\fontname\font\\
fontsize = 12pt \includestandalone{pic\jobname}

\huge       \fontname\font\\ fontsize huge \includestandalone{pic\jobname}

\tiny\fontname\font\\ fontsize tiny \includestandalone{pic\jobname}
\end{document}

• Thanks for the comprehensive answer. I will take some time to completely understand it then get back in case of further inquiries. – Diaa Dec 15 '20 at 13:16
• Unknowingly, none of your MWEs worked as expected for me and I get an error indicating that \usetikzlibrary is undefined. For instance, the log file of your case (d) can be found here pastebin.com/as6uxQWm. – Diaa Dec 16 '20 at 11:36
• @Diaa, in standalone file is not loaded tikz package. try to ad tikz as option to standalone document class: \documentclass[tikz]{standalone} – Zarko Dec 16 '20 at 13:22
• @Zarko The output will be worse than what I posted in my question. – Diaa Dec 16 '20 at 13:42
• @Diaa, to be honest, I didn't check how your question nor answer. So my conclusion after only look code in answer was wrong. On my PC answer works without errors, however it also work if I add tikz package as I mentioned. I test with today upgraded MikTeX (20.12). – Zarko Dec 16 '20 at 13:53