Here is a key-value interface, which, as Joseph Wright has said, appears to be the way to get a solution to your problem.
\documentclass{article}
\usepackage{keyreader}
\makeatletter
\def\msg#1{\ifkrdindef\else Option chosen: #1\endgraf\fi}
\krddefinekeys{gitano}{%
choice/name/option1/{
option1.do=\msg{1},
option2.do=\msg{2},
option3.do=\msg{3},
option4.do=\msg{4},
option5.do=\msg{5}
}
;
}
% Example command, to reformat the list, process the keys, and print the results:
\newcommand\gitanooptions[1][]{%
\krdifblank{#1}{%
\krdsetkeys{gitano}{name=option1}%
}{%
\def\tempa##1=##2=##3\@nil{\unexpanded{##2}}%
\edef\tempa{\tempa#1==\@nil}%
\ifx\tempa\@empty
\krdsetkeys{gitano}{name=option1}%
\else
\def\tempb{}%
\@for\tempa:=\tempa\do{%
\edef\tempb{%
\unexpanded\expandafter{\tempb}%
\ifx\tempb\@empty\else,\fi
name=\unexpanded\expandafter{\tempa}%
}%
}%
\krdexpanded{\noexpand\krdsetkeys{gitano}{\tempb}}%
\fi
}%
}
\makeatother
% Examples:
\begin{document}
\gitanooptions[name={option1,option2}]
\gitanooptions[name]
\gitanooptions[name=option3]
\gitanooptions[name=option4]
\gitanooptions[name={option2,option5}]
\gitanooptions
\end{document}
\newbool{mybool}
is almost the same as \newif
, but it checks whether \ifmybool
is already defined, which LaTeX doesn't:
\newrobustcmd*{\newbool}[1]{%
\expandafter\@ifdefinable\csname if#1\endcsname{%
\expandafter\newif\csname if#1\endcsname}}
There's also \providebool
which does nothing if the conditional is already defined.
Similarly, \ifbool
is a wrapper around the usual construction
\if...
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
with a preliminary check whether the conditional is defined. So it can be used also for primitive conditionals:
\ifbool{hmode}{<something for horizontal mode>}{<something else>}
Instead \newtoggle{mytoggle}
is defined by
\newrobustcmd*{\newtoggle}[1]{%
\ifcsdef{etb@tgl@#1}
{\etb@error{Toggle '#1' already defined}\@eha}
{\cslet{etb@tgl@#1}\@secondoftwo}}
so it checks whether the toggle is already defined and, if not, it sets it to "false". The constructed macro \etb@tgl@mytoggle
is either \@firstoftwo
(corresponding to "true") or \@secondoftwo
(corresponding to "false"). When one says
\iftoggle{mytoggle}{<true>}{<false>}
etoolbox
simply checks whether the toggle is defined and, if it is, just puts \etb@tgl@mytoggle
in the input stream, thus doing "the right thing", because it chooses either <true>
or <false>
depending if it is \@firstoftwo
or \@secondoftwo
.
Note that \toggletrue
is defined as
\newrobustcmd*{\toggletrue}[1]{%
\ifcsdef{etb@tgl@#1}
{\cslet{etb@tgl@#1}\etb@toggletrue}
{\etb@noglobal\etb@err@notoggle{#1}}}
so it can be preceded by \global
: indeed \ifcsdef
is expandable, so if the toggle foo
is not defined, after \global\toggletrue{foo}
we'd remain with
\global\etb@noglobal\etb@err@notoggle{#1}}
which becomes
\global\let\relax\relax\etb@err@notoggle{#1}
that effectively removes the \global
by doing a harmless \let
(almost harmless, because it can impact on the stack memory, but since there's an error raised anyway, the user will correct it). If instead the toggle \foo
is defined, we remain with
\global\cslet{etb@tgl@foo}\etb@toggletrue
so, again,
\global\expandafter\let\csname etb@tgl@foo\endcsname\etb@toggletrue
where \etb@toggletrue
is the same as \@firstoftwo
. The same holds, of course, for \togglefalse
.
Which one to prefer? If you plan to use also the traditional \if...
syntax, then \newbool
is needed. Otherwise it's just a matter of personal preference.
Both booleans and toggles can be used in boolean expression (\ifboolexpr
), so there's no difference for that usage either. Note that \global\booltrue
and \global\boolfalse
are legal too.
Best Answer
The main problem is that
\pageref{LastPage}
cannot be used in the argument of\ifthenelse
, nor in theetoolbox
functions, because it's only good for printing the page reference.One has to use a different approach, with the safer package
zref-lastpage
.Instead of
\ifnum
the correspondingetoolbox
function can be usedHowever this still requires
\makeatletter
and\makeatother
and\AtBeginDocument
like the code above, because we have to ensure the code is executed after the.aux
file has been read in.Uncommenting the lines with
%
will show the page number on both pages; as it is no page number will be printed.