Skip to main content
added 148 characters in body
Source Link
Ulrich Diez
  • 32.7k
  • 2
  • 34
  • 63

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[{#1}]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[{#1}]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% % \exp_args:Ne fully expands the argument passed to \str_case:nnTF. \exp_args:Ne  \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} } \cs_new:Npn \RandomVar #1 {% % \exp_args:Ne fully expands the argument passed to \str_case:nnTF. \exp_args:Ne  \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} } \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[{#1}]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[{#1}]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} } \cs_new:Npn \RandomVar #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} } \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[{#1}]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[{#1}]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% % \exp_args:Ne fully expands the argument passed to \str_case:nnTF. \exp_args:Ne  \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} } \cs_new:Npn \RandomVar #1 {% % \exp_args:Ne fully expands the argument passed to \str_case:nnTF. \exp_args:Ne  \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} } \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

added 2 characters in body
Source Link
Ulrich Diez
  • 32.7k
  • 2
  • 34
  • 63

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[#1]%[{#1}]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[#1]%[{#1}]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} }% \cs_new:Npn \RandomVar #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} }% \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[#1]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[#1]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} }% \cs_new:Npn \RandomVar #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} }% \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[{#1}]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[{#1}]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} } \cs_new:Npn \RandomVar #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} } \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

added 641 characters in body
Source Link
Ulrich Diez
  • 32.7k
  • 2
  • 34
  • 63

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[#1]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[#1]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} }% \cs_new:Npn \RandomVar #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} }% \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[#1]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[#1]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here

Seems making commands robust by defining via \NewDocumentCommand instead of \newcommand does the trick.

\documentclass{article} %\usepackage{xparse} \usepackage{xstring} \NewDocumentCommand{\Prob}{m}{% \IfEqCase{#1}{% {1}{p}% {2}{q}% {3}{r}% }[#1]% }% \NewDocumentCommand{\RandomVar}{m}{% \IfEqCase{#1}{% {1}{X}% {2}{Y}% {3}{Z}% }[#1]% }% \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

The last line yields p_{\RandomVar1,\RandomVar2} which in turn yields p_{X,Y}.

enter image description here


A better approach might be using expandable \str_case:nnTF:

\documentclass{article} \ExplSyntaxOn \cs_new:Npn \Prob #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {p} {2} {q} {3} {r} } {} {#1} }% \cs_new:Npn \RandomVar #1 {% \exp_args:Ne \str_case:nnTF {#1} { {1} {X} {2} {Y} {3} {Z} } {} {#1} }% \ExplSyntaxOff \begin{document} $\Prob1$, $\Prob2$, $\Prob{p_{X,Y}}$, $p_{\RandomVar1, \RandomVar2}$ $\Prob{p_{\RandomVar1,\RandomVar2}}$ \end{document} 

enter image description here

Source Link
Ulrich Diez
  • 32.7k
  • 2
  • 34
  • 63
Loading