Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Can case-selecting functions like \prg_case_int or \prg_case_str be nested? If so I will provide some examples of very weird results I observe with nesting.

REVISION:

I messed up the syntax suggested in the interface3 document by omitting some of the <code case> strings. The revised code of my experiment now works and looks like this:

%document name: LaTeX3_interface3.tex
%RN 15/3/2012
%   OBJECTIVE: Nesting case-selecting functions prg_case_str or prg_case_int.
%   REFERENCE: The LaTeX3 Intefaces, 8 Feb 2012 (interface3.pdf), page 38ff.
%   COMMENTS: 
%   (1) on the first attempt failed to define all of the <code case> strings and the whole 
%   thing turned pear shaped
%   (2) the printed messages in the result are not properly formatted but that's due 
%   to my inexperience in LaTeX2 and needs to be addressed seperately.
%=====================================================================================

\documentclass{article}
%\usepackage{expl3}
\usepackage{amsmath,xparse} 
\ExplSyntaxOn 
\NewDocumentCommand{\myCommand}{ m m m } 
{ 
   \prg_case_str:nnn { #1 }
{
    {1a} 
    {
        \prg_case_str:nnn { #2 }
        {
            {2A} %{case 1a:2A\\}
            {
                \prg_case_str:nnn { #3 }
                {
                    {3\alpha}   {case 1a:2A:3\alpha\\}
                    {3\beta}    {case 1a:2A:3\beta\\}
                    {3\gamma}   {case 1a:2A:3\gamma\\}                  
                }
                    {None of 1a:2A: 3\alpha, 3\beta, 3\gamma \\}
            }
            {2B} %{case 1a:2B\\}
            {
                \prg_case_str:nnn { #3 }
                {
                    {3\alpha}   {case 1a:2B:3\alpha\\}
                    {3\beta}    {case 1a:2B:3\beta\\}
                    {3\gamma}   {case 1a:2B:3\gamma\\}                  
                }
                    {None of 1a:2B: 3\alpha, 3\beta, or 3\gamma\\}
            }
            {2C} %{case 1a:2C\\}
            {
                \prg_case_str:nnn { #3 }
                {
                    {3\alpha}   {case 1a:2C:3\alpha\\}
                    {3\beta}    {case 1a:2C:3\beta\\}
                    {3\gamma}   {case 1a:2C:3\gamma\\}                  
                }
                    {None of 1a:2C: 3\alpha, 3\beta, 3\gamma\\}
            }
        } 
            {None of 1a: 2A, 2B, 2C\\}
    }
    {1b} 
    {
        \prg_case_str:nnn { #2 }
        {
            {2A}    {case 1b:2A\\}
            {2B}    {case 1b:2B\\}
            {2C}    {case 1b:2C\\}
        } 
            {None of 1b: 2A, 2B, 2C\\}
    }
    {1c} 
    {
        \prg_case_str:nnn { #2 }
        {
            {2A}    {case 1c:2A\\}
            {2B}    {case 1c:2B\\}
            {2C}    {case 1c:2C\\}
        } 
            {None of 1c: 2A, 2B, 2C\\}
    }
}
    {None of 1a, 1b, 1c\\}
}
%etc. etc.
\ExplSyntaxOff 

\begin{document}

$\myCommand{1a}{2A}{3\alpha}$
$\myCommand{1a}{2B}{3\beta}$
$\myCommand{1a}{2C}{3\gamma}$
$\myCommand{1b}{2A}{3gamma}$
$\myCommand{1b}{2B}{3gamma}$
$\myCommand{1b}{2C}{3gamma}$
$\myCommand{x}{2A}{3gamma}$
$\myCommand{1a}{y}{3gamma}$
$\myCommand{1a}{2C}{3gamma}$
$\myCommand{1b}{2A}{3gamma}$
$\myCommand{z}{2B}{3gamma}$
$\myCommand{1b}{2C}{3gamma}$

\end{document}

If I knew how to import the resulting .pdf document I would.

My apologies for starting a wild goose chase. My only excuse is that the LaTeX syntax is quite tricky to get right in the absence of automated editing facilities that would as a minimum generate correct indentations. Perhaps such LaTeX3 editing facilities are already available, if they are I would love to hear about them.

share|improve this question

closed as too localized by Werner, egreg, Andrey Vihrov, Joseph Wright Mar 16 '12 at 8:51

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Of course they can. What are these examples? –  egreg Mar 15 '12 at 15:37
2  
yes please provide them, as always there my be bugs but I'm not aware any offcial restrictions –  Frank Mittelbach Mar 15 '12 at 16:06
    
Obviously I am doing something very stupid with my syntax here. I'll try to fix it before I ask for more help. Thanks. –  Reinhard Neuwirth Mar 15 '12 at 21:33
    
OK, I made it work. I had left out some of the <code case> strings. Would like to send you my code example but it is too big to fit into this COMMENT. Should I make this a new question or what other options do I have to send my code? –  Reinhard Neuwirth Mar 15 '12 at 23:18
    
@ReinhardNeuwirth: It seems like you've solved your original problem. As such, I'm voting to close this question. –  Werner Mar 16 '12 at 7:05

Browse other questions tagged or ask your own question.