[Tex/LaTex] Best way to include a standalone tikz file and scale it without scaling the nodes

standalonetikz-pgf

Consider something like this:

\documentclass{article}
\usepackage{standalone}
\begin{document}
\includestandalone[scale=2]{myfile}
\includestandalone[scale=1.5]{myfile}
\end{document}

where myfile is a standalone file containing a tikz picture:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (1,0) node[right]{$X$};
\end{tikzpicture}
\end{document}

My problem is, that the scale option scales the whole picture including nodes and the characters like $X$ in my example. What is the best way to change this such that I can scale the picture without scaling the nodes? I.e. the equivalent to the scale option of the tikzpicture environment without the transform shape option?

Best Answer

Why not something like this?

\newcommand*\MyScale{1}
\newcommand*\Scale[1][1]{\renewcommand*\MyScale{#1}}
\tikzset{%
  every picture/.style={%
    scale=\MyScale,
  }
}

This defines a command \Scale which takes a single optional argument. By default, it just sets the scaling to 1. With an argument, it sets it to that value. This is then used at the start of each tikzpicture to scale the picture without, of course, scaling the text and labels.

So you can then say

  \includestandalone{\jobname-tikz}
  \Scale[2]
  \includestandalone{\jobname-tikz}
  \Scale[1.5]
  \includestandalone{\jobname-tikz}
  \Scale[3]
  \includestandalone{\jobname-tikz}
  \Scale
  \includestandalone{\jobname-tikz}

to produce

unscaled nodes

I would like this to reset the default scaling each time. However, I can't figure out a straightforward way to do that right now and the feature doesn't seem to be worth the additional hassle involved in using a non-straightforward strategy.

Complete code:

\begin{filecontents}{\jobname-tikz.tex}
\documentclass[tikz]{standalone}
\begin{document}
  \begin{tikzpicture}
    \draw (0,0) -- (1,0) node[right]{$X$};
  \end{tikzpicture}
\end{document}
\end{filecontents}
\documentclass{article}
\usepackage{standalone,tikz}
\newcommand*\MyScale{1}
\newcommand*\Scale[1][1]{\renewcommand*\MyScale{#1}}
\tikzset{every picture/.style={scale=\MyScale}}
\begin{document}
  \includestandalone{\jobname-tikz}
  \Scale[2]
  \includestandalone{\jobname-tikz}
  \Scale[1.5]
  \includestandalone{\jobname-tikz}
  \Scale[3]
  \includestandalone{\jobname-tikz}
  \Scale
  \includestandalone{\jobname-tikz}
\end{document}