I would like to divide a list of parameters for a series of tikz graphics into a bunch of separate, named tex files.
Specifically: each parameter file should be loaded by an \input
command which in turn is contained inside the definition of one cumulative \newcommand
, see setspecs-command.tex below.
The \newcommand
is itself loaded via another \input
in the main.tex file.
I naively thought the \newcommand
parameter numbers e.g. #1
would work inside the inputted files, but I am getting the error message:
./parameters1.tex:5:
Illegal parameter number in definition of \tikz@math@marshal.
A related error message:
./parameters1.tex:1: You can't use `macro parameter character #' in horizontal mode.
comes from printing the parameter value inside the inputted file, e.g. by inserting the line:
Parameter file #1 was loaded.
before the \tikzmath
environment in parameters1.tex.
Any thoughts on how to deal with \newcommand
macro parameters inside a file loaded via \input
?
Full MWE below:
main.tex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{math}
%%
%Courtesy of egreg, see https://tex.stackexchange.com/questions/415138
\usepackage{pdftexcmds}
\makeatletter
\newcommand{\strequal}[2]{\pdf@strcmp{#1}{#2}==0}
\makeatother
%%
\input{setspecs-command}
\begin{document}
First graphic:\\
\setspecs{parameters2}
\begin{tikzpicture}
\draw (-2,-2) rectangle (2,2);
\node at (0,0) {\var};
\end{tikzpicture}
\clearpage
Then second graphic:\\
\setspecs{parameters1}
\begin{tikzpicture}
\draw (-2,-2) rectangle (2,2);
\node at (0,0) {\var};
\end{tikzpicture}
\end{document}
The file containing the definition of the setspecs command:
setspecs-command.tex
\newcommand\setspecs[1]{
\input{parameters1}
\input{parameters2}
%... further files to be added as and when needed
}
Two examples of the parameter files below:
parameters1.tex
%Parameter file #1 was loaded.
%All parameter files will have the following overarching structure
\tikzmath{
if \strequal{#1}{parameters1} then {
\var = 111;
};
}
parameters2.tex
\tikzmath{
if \strequal{#1}{parameters2} then {
\var = 222;
};
}
Best Answer
It works with the following code in
setspecs-command.tex
, although I don't fully understand what you're trying to accomplish.You need to add
\usepackage{catchfile}
to the document preamble.You may be interested in a much simpler code:
The contents of
parameters1.tex
andparameters2.tex
are exactly the same.The idea is exactly the same as before, but the
expl3
code is more transparent with respect to “doubling the#
’s”.