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;
};
}
pgfkeys
looks to be a better approach. If you really do need to do it this way it would be simpler, and much more efficient, to have\setspecs
input only the required file. Something like\newcommand\setspecs[1]{\input{parameter#1}}
, although you might need some\expandafter
s to make this work in practise. Will look tomorrow to see if no one else has answered.pgfkeys
(thanks!) from this post and unfortunately my basic issue persists. When I put the contents of the\newcommand
definition inside an inputted file, parameters such as#1
aren't recognized. But I am hoping someone here knows the right syntax, viz. your\expandafter
comment.