I wrote this code to expose the issue I'm facing:
Code: Select all
Code, edit and compile here:
\documentclass[test]{article}\makeatletter\DeclareOption{test}{\@testtrue}\ProcessOptions\newcommand{\Item}{\if@test t&t&t&t \else 21&22&23&24 \fi}\makeatother\begin{document}\begin{tabular}{cccc}11 & 12 & 13 & 14 \\\Item\end{tabular}\end{document}
The errors were:
! Incomplete \iftrue; all text was ignored after line 12.
! Extra alignment tab has been changed to \cr
! Extra \fi.
! Missing \cr inserted.
...
The problem here is the presence of '&' inside \if conditional, but with ifthen or etoolbox the issue disappears:
Code: Select all
Code, edit and compile here:
\documentclass[test]{article}\usepackage{ifthen}\usepackage{etoolbox}\makeatletter\def\XXX{i}\newif\if@test \@testfalse\newtoggle{test}\DeclareOption{test}{\@testtrue\def\XXX{j}\toggletrue{test}}\ProcessOptions\newcommand{\Item}{\if@test t&t&t&t \else 21&22&23&24 \fi}\newcommand{\ItemI}{\ifthenelse{\equal{\XXX}{j}}{t&t&t&t}{31&32&33&34}}\newcommand{\ItemE}{\iftoggle{test}{t&t&t&t}{41&42&43&44}}\makeatother\begin{document}\begin{tabular}{cccc}11 & 12 & 13 & 14 \\\Item \\\ItemI \\\ItemE\end{tabular}\end{document}
Thanks.