Here is an example of the approach mentioned in the comments.
For each value <foo>
of the enumeration, we define a new function \c_<foo>_manuscript
which has \c_<foo>_manuscript_undefined:
as its replacement text. (The real quark-like approach would be making it expand to \c_<foo>_manuscript
itself, but in my experience expanding to an undefined control sequence works equally fine and is easier to debug in case of an unexpected expansion of the function.)
So the "enumeration" looks like
\cs_new_protected:Npn \c_short_manuscript { \c_short_manuscript_undefined: }
\cs_new_protected:Npn \c_medium_manuscript { \c_medium_manuscript_undefined: }
\cs_new_protected:Npn \c_long_manuscript { \c_long_manuscript_undefined: }
Storing one of these values works by \let
-assigning a control sequence to the corresponding constant:
\cs_set_eq:NN \g__callegar_cur_manuscript \c_medium_manuscript
Finally, to check the current value against a certain constant, we use
\cs_if_eq:NNTF \g__callegar_cur_manuscript \c_medium_manuscript { true } { false }
Full example document:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
% The "enumeration" values
\cs_new_protected:Npn \c_short_manuscript { \c_short_manuscript_undefined: }
\cs_new_protected:Npn \c_medium_manuscript { \c_medium_manuscript_undefined: }
\cs_new_protected:Npn \c_long_manuscript { \c_long_manuscript_undefined: }
% CS holding the current manuscript type value
\cs_set_eq:NN \g__callegar_cur_manuscript \c_medium_manuscript
% Set current manuscript type
\NewDocumentCommand \SetManuscriptType { m } {
\cs_if_exist:cTF { c_#1_manuscript }
{ \cs_set_eq:Nc \g__callegar_cur_manuscript { c_#1_manuscript } }
{ \PackageError { callegar } { Manuscript~type~`#1'~not~defined } { } }
}
% Switch over the current manuscript type
\NewDocumentCommand \SwitchManuscriptType { +m+m+m } {
\cs_if_eq:NNTF \g__callegar_cur_manuscript \c_short_manuscript { #1 } {
\cs_if_eq:NNTF \g__callegar_cur_manuscript \c_medium_manuscript { #2 } {
\cs_if_eq:NNTF \g__callegar_cur_manuscript \c_long_manuscript { #3 }
{ \PackageError { callegar } { Unknown~manuscript~type~set } { } }
}
}
}
\ExplSyntaxOff
\begin{document}
Current manuscript type: \SwitchManuscriptType{short}{medium}{long}
\SetManuscriptType{short}
Current manuscript type: \SwitchManuscriptType{short}{medium}{long}
\SetManuscriptType{long}
Current manuscript type: \SwitchManuscriptType{short}{medium}{long}
%\SetManuscriptType{extralong}
\end{document}

short
,medium
,long
? That would naturally be stored as\c_my_format_tl
then can be checked using case function or a name lookup (\use:c { ...}
).\int_new:N \c_state_int \if_case:w \c_state_int <case 0> \or: <case 1> \or: ... \else: <default> \fi:
is by far the fastest.\c_state_a:
,\c_state_b:
etc., and then checked against them via\cs_if_eq:NN(TF)
.\tl_set_eq:NN \g_xxx_state_switch \c_xxx_state_loong
getting thelong
wrong, you immediately error out. Conversely if you use plain strings as in\tl_gset:Nn \g_xxx_state_switch { loong }
you only catch the error at usage time or in the worse case you get strange behavior.