# Is there a gentle introduction to learning expl3 syntax [duplicate]

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.

• Have you seen this question? tex.stackexchange.com/questions/84605/programming-with-latex3 Jan 13, 2013 at 8: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 Jan 13, 2013 at 8: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. Jan 13, 2013 at 8: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. Jan 13, 2013 at 9: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 Jan 13, 2013 at 18:12