Interaction Between LaTeX \ifcase Primitive and Macro Expansion in Nested Conditionals
0 reputation · 09 Nov 2021, 03:27 UTC
The goal is to clarify how the \ifcase primitive processes its argument when that argument is a macro that itself expands to an integer, particularly in nested conditional constructs.
During TeX's expansion phase, \ifcase evaluates an integer expression to select a branch; however, the interaction with macro expansion is not fully documented, leaving uncertainty about whether the argument is expanded recursively until a non‑expandable integer is obtained, or only a single expansion step is performed before evaluation.
Additionally, when \ifcase appears inside another conditional, the combined expansion depth may approach TeX's memory limits, raising questions about practical limits and error handling.
Does TeX fully expand the \ifcase argument before evaluating the integer, or does it stop after the first expansion step? What occurs if the macro expands to a token list that yields an integer only after further expansion versus a non‑expandable token? Are there defined limits on expansion depth for nested \ifcase usage that could trigger a memory overflow?