I try to create a command if...else which seems correct when i expand it in body but not in preamble. The package answers seems to be not include because the \Newassociation command is unknown. I try to use \ifodd directly and it works but il would understand my error (quoting, escaping, ... ?).
Log of pdflatex
! Missing number, treated as zero.
<to be read again>
{
l.14 ...tionfiles]{answers}}{\usepackage{answers}}
(/usr/local/texlive/2017/texmf-dist/tex/latex/answers/answers.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/tools/verbatim.sty))
! Undefined control sequence.
l.29 \Newassociation
{SOL}{Solution}{tempo}
LaTeX code
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\newlength{\personnelmm}
\setlength{\personnelmm}{1pt}
\newcommand{\ifpersonnel}[2]
{\ifodd\personnelmm{#1}\else{#2}\fi}
\ifpersonnel{\usepackage[nosolutionfiles]{answers}}{\usepackage{answers}}
% \ifodd\personnelmm
% \usepackage[nosolutionfiles]{answers}
% \typeout{THEN}
% \else
% \typeout{ELSE}
% \usepackage{answers}
% \fi
\Newassociation{SOL}{Solution}{tempo}
\renewcommand{\Solutionlabel}[1]{\textbf{Solution #1}}
\begin{document}
...
\setlength{\personnelmm}{1pt}
then\ifodd\personnelmm
is false as it will be cast tosp
by multiplying by 2^{16}, and whether it is true or false you are using\usepackage
inside a local{}
group so most of the definitions made by the package will be discarded.etoolbox
and itstoggle
s. But you could also useexpl3
and its vast array of conditionals and programming tools. Those solution offer a slightly more LaTeX-y syntax and are more natural than using lengths for a true/false switch.\setlength{\personnelmm}{1sp}
would work; but why not just doing\newcommand{\personnelmm}{1}
?