# \IfStrEqCase redefines #1

What is the meaning of #1, #2, etc in the optional parameter of \IfStrEqCase?

This required me to use a ##1 instead of #1 within \pgfplotsinvokeforeach which I was not expecting.

I would have expected #1 to be undefined as it is outside of \IfStrEqCase. I have added a more elaborate test whose output is

Seems a little bizarre to me that I can use #1 when invoking a macro? Are there other macros that I can invoke which have similar behavior? And the behavior seems different if I use \IfStrEqCase within a macro.

## Code:

\documentclass{article}
\usepackage{xstring}

\begin{document}
\IfStrEqCase{5}{
{1}{}%
{2}{}%
}[{
param 1 = #1,\par
param 2 = #2,
}]
\end{document}


## Code: More Elaborate Test Case

\documentclass{article}
\usepackage{xstring}

\newcommand*{\PrintFirstParamaterIfNotOneOrTwo}[1]{%
\IfStrEqCase{#1}{
{1}{x}%
{2}{y}%
}[{
param 1 = #1,\par
}]
}

\begin{document}
\IfStrEqCase{xxxx}{
{1}{x}%
{2}{y}%
}[{
param 1 = #1,\par
}]

\PrintFirstParamaterIfNotOneOrTwo{xxxx}
\end{document}

• as the xstring macros are not expandable and make many internal definitions the treatment of # is well defined but essentially arbitrary and just reflects the internal implementation. – David Carlisle May 18 '18 at 8:43

## 1 Answer

If you change to

    {1}{x}%
{2}{y}%


you will see #1 is 2 and #2 is y, you say that isn't what you expected, but you didn't say what you did expect?

• I would expect it to trigger an error just as it would outside of \IfStrEqCase. What was not obvious was why \pgfplotsinvokeforeach{1,2,...,\MaxCount}{ p#1 } with the pgfplots package loaded was starting at p3 instead of p1 until I change it to p##1. – Peter Grill May 18 '18 at 9:22
• Added a more elaborate test case that hopefully shows why I think this is confusing. Perhaps there is something really basic that I am misunderstanding. – Peter Grill May 18 '18 at 9:35