I created some new commands that take arguments. Several of my commands take the same (lengthy) arguments. Because of this I put those arguments in a separate file. But I seem unable to input or import these arguments.
main.tex:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\myfirsttask}{m m m g}{
#1 #2 #3
% do stuff
\IfNoValueF{#4}{%
#4
% do stuff
}
}
\NewDocumentCommand{\mysecondtask}{m m m g}{
#1 #2 #3
% do stuff
\IfNoValueF{#4}{%
#4
% do stuff
}
}
\NewDocumentCommand{\myfirst}{m}{
\expandafter\myfirsttask\input{#1}
}
\NewDocumentCommand{\mysecond}{m}{
\expandafter\mysecondtask\input{#1}
}
\ExplSyntaxOff
\begin{document}
\myfirst{argumentsFile}
\mysecond{argumentsFile}
\end{document}
argumentsFile.tex:
{first argument}%
{second argument}%
{third argument}%
{optional argument}
At first I did not use \expandafter
and got:
Runaway argument?
! Paragraph ended before \myfirsttask was complete.
<to be read again>
\par
I assumed that \myfirsttask
and \mysecondtask
dit not have enough arguments as the contents of the argumentsFile were not yet inserted. Therefore I added \expandafter
as to insert the argumentsFile before expanding \myfirsttask
and \mysecondtask
. This however gives me
! LaTeX Error: File `-NoValue-.tex' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: tex)
Enter file name:
! Emergency stop.
<read *>
l.34 \myfirst{argumentsFile}
I assume that's because the curly braces in my argumentsFile were removed by the expansion of \input
???
Does anyone know how I could correctly import/input command arguments?