使用 \ifcase 字符文字

使用 \ifcase 字符文字

有没有办法在 LaTeX 中实现类似 switch 的宏,或者我必须嵌套 if?

看起来像这样:

 \ifcase#1
   \case a{}
   \or\case b{}
   \or\case c{}
 \fi

如果没有,您能给我一个解决方案吗?最好是可以在 vanilla-LaTeX 上运行的程序?

答案1

\def\foo#1{%
 \ifcase\numexpr`#1 - `a\relax
       case a
   \or case b
   \or case c
 \fi}

然后\foo{b}可能扩展为case b

相关内容