2

I need to dynamically input a proper .tex file into my document. I wrote the following code that works only if instead of "\realyear{\season}" I explicitly write 2019. Inside the \input all new defined commands work, but the command that has one argument (which is \realyear) makes the document not to compile (error is "Argument of \filename@simplehas an extra }"). Why is that? How to overcome this issue?

\def \myfolder {../../../../../trial}
\def \season {Spring}
\def \yearstart{2018}
\def \yearfinish{2019}

\newcommand{\realyear}[1]{%
  \ifthenelse{\equal{\detokenize{#1}}{\detokenize{Spring}}}
    {\yearstart}
    {\yearfinish}%
}

\input{\myfolder/trialfolder/\season\realyear{\season} common}  
1
  • \ifthenelse is not expandable. It won't work here. Oct 20, 2018 at 3:08

2 Answers 2

2

The \ifthenelse command doesn't work by expansion, so it cannot work in that position.

While \pdfstrcmp works, it has a couple of disadvantages: it is not “engine independent” and has a weird syntax.

One can use etoolbox

\usepackage{etoolbox}

\newcommand{\realyear}[1]{\ifstrequal{#1}{Spring}{\yearstart}{\yearend}}

or expl3

\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN \equalstringTF \str_if_eq:nnTF
\ExplSyntaxOff

\newcommand{\realyear}[1]{\equalstringTF{#1}{Spring}{\yearstart}{\yearend}}
3

You need an expandable option for returning \yearstart or \yearfinish. Here's an option:

\def\season{Spring}
\def\yearstart{2018}
\def\yearfinish{2019}

\newcommand{\realyear}[1]{%
  \ifnum\pdfstrcmp{#1}{Spring}=0
    \yearstart
  \else
    \yearfinish
  \fi
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .