I have one main document and two standalone files of tikz pics as given in this answer. I need to have \newlength
in the main document and all the standalone files in order to be able to run any document on its own without the need to change the main document structure every single time.
However, relaxing lengths as shown in this answer doesn't work for me. So, how can both cases be integrated to work flawlessly?
Main Document
\documentclass{article}
\usepackage{tikz}
\usepackage[subpreambles=true]{standalone}% I need subpreambles to be true
\begin{document}
% I need to keep the following definitions
\newlength{\mylength}
\setlength{\mylength}{1cm}
\let\mylength\relax
\begin{figure}
\includestandalone[width=\textwidth]{myfrsttikz}
\caption{My First TikZ picture}
\end{figure}
\begin{figure}
\includestandalone[width=\textwidth]{mysecondtikz}
\caption{My Second TikZ picture}
\end{figure}
\end{document}
First Standalone TikZ File
% myfrsttikz.tex %
\documentclass{standalone}
\newlength{\mylength}
\setlength{\mylength}{2cm}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (\mylength,\mylength);
\end{tikzpicture}
\end{document}
Second Standalone TikZ File
% mysecondtikz.tex %
\documentclass{standalone}
\newlength{\mylength}
\setlength{\mylength}{5cm}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (\mylength,\mylength);
\end{tikzpicture}
\end{document}
\providelength
in the main document.