5

Possible Duplicate:
Programming with LaTeX3

I was going to post a question about creating a switch within a command to determine formatting for a command and came across the following link String test, with complicated arguments in which I discovered the expl3 equivalents of \makeatletter and \makeatother in \ExplSyntaxOn and \ExplSyntaxOff. So I tried to make my command as follows:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\mytestcmd}{ O{a} m}
    {
        \prg_case_str:nnn { #1 }
        {
            { a } { A }
            { b } { B }
            { c } { CC }
            { d } { DED }
        }
        :#2
    }
\ExplSyntaxOff
\begin{document}

\mytestcmd{Hello}

\mytestcmd[b]{Hello}

\mytestcmd[c]{Hello}

\mytestcmd[d]{Hello}

\end{document}

But then I got the unexpected result that my colon from :#2 was not showing up in the actual rendered text. I'm sure there's a simple solution for this. I'm not actually so interested in someone telling me how to fix is particular issue with the colon.

However, I do find the expl3 documentation quite daunting. Is there an expl3 primer or some kind of expl3 for dummies around where I can learn some thing without feeling like I'm drowning?

Incidentally, normally I would handle the switch as in the following MWE:

\documentclass{article}
\usepackage{xparse}
\makeatletter
\def\my@test@cmd@a{a}
\def\my@test@cmd@b{b}
\def\my@test@cmd@c{c}
\def\my@test@cmd@d{d}
\NewDocumentCommand{\mytestcmd}{ O{a} m}
    {%
        \def\my@test@cmd{#1}%
        \ifx\my@test@cmd\my@test@cmd@a{A}\fi%
        \ifx\my@test@cmd\my@test@cmd@b{B}\fi%
        \ifx\my@test@cmd\my@test@cmd@c{C}\fi%
        \ifx\my@test@cmd\my@test@cmd@d{D}\fi%
        :#2%
    }
\makeatother
\begin{document}

\mytestcmd{Hello}

\mytestcmd[b]{Hello}

\mytestcmd[c]{Hello}

\mytestcmd[d]{Hello}

\end{document}

What I like about the expl3 syntax is it seems to be much kinder in building a true switch than my work around.

A.Ellett
  • 50,533
  • Have you seen this question? http://tex.stackexchange.com/questions/84605/programming-with-latex3 – Torbjørn T. Jan 13 '13 at 08:04
  • @TorbjørnT. No. I hadn't see that. Hmmm. Should I remove my question as the duplicate? Or should it be flagged as a duplicate to help someone else find that link? I sadly did not think to search on latex3 – A.Ellett Jan 13 '13 at 08:07
  • BTW, you can \IfEqCase from the xstring package can be used to case type statements. See for example Making switch/case with etoolbox's \ifdefequal. BTW, I'd recommend you not delete the question as others may come across this in their search and then will can follow the duplicate link. – Peter Grill Jan 13 '13 at 08:12
  • @A.Ellett Two points about your specific case. First, \prg_case_str:nnn got renamed as \str_case:nnn a while ago. Second, this function requires three arguments (nnn) and you've only given two. So the : is taken as the third one, which is why it vanishes. You need an empty argument ({ }) after the end of the cases. – Joseph Wright Jan 13 '13 at 09:02
  • @JosephWright, Trying to follow your suggestions, I only just updated my LiveTex version last week, yet neverthess when I run tex on \str_case:nnn it complains about an undefined control sequence. Despite this, I appreciate your help – A.Ellett Jan 13 '13 at 18:12
  • @A.Ellett That will depend on what you mean by 'updated your TeX Live'. The TL2012 DVD version was frozen in July 2012, and we deliberately did not make this change until just after that. So if you have the DVD version the old name will still stand. – Joseph Wright Jan 13 '13 at 20:07
  • @JosephWright. I downloaded TL2012 from what's posted on the mactex website: though that may just be the same thing that is on the DVD. After downloading it, I ran tlmgr update --self. – A.Ellett Jan 13 '13 at 20:17
  • @A.Ellett tlmgr update --self updates tlmgr itself, but not anything installed. You'd need tlmgr update --self --all to update your packages. – Joseph Wright Jan 13 '13 at 20:19

0 Answers0