0

I get the message

! Missing \endcsname inserted.
<to be read again> 
                   \delimiter 
l.58 ...ore than two arguments for {\backslash}Id}

? 

For this document

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse} % loads expl3
%See interface3.pdf

\ExplSyntaxOn

\NewDocumentCommand \Id {O{}}
  {
     \Id:n {#1}
  }

\cs_new:Npn \Id:n #1
  {
    \clist_set:Nn \l_tmpa_clist {#1}
    \int_case:nnF
      {\clist_count:N \l_tmpa_clist}
      {
        {0}
        {
         \operatorname{Id}
        }
        {1}
        {
         \operatorname{Id} \sb {#1}
        }
        {2}
        {
         \operatorname{Id}
           \sp {\clist_item:Nn \l_tmpa_clist 1}
           \sb {\clist_item:Nn \l_tmpa_clist 2}
        }
      }
      {
          \msg_error:nn {shmuel} {More than two arguments for {\backslash}Id}
      }
  }

\ExplSyntaxOff

\ExplSyntaxOn
\msg_new:nnn {shmuel} {short} {##1}
\msg_new:nnnn {shmuel} {long} {##1} {##2}
\ExplSyntaxOff

\begin{document}

Test $\Id$, $\Id[A]$ and $\Id[{A,B}]$ inline.
\begin{equation}
  \text{Test} \ \Id, \\
   \Id[A], \\
   \Id[{A,B}]
\end{equation}

%Test $\Id[{too},{many},{parms}]$

\ExplSyntaxOn
\msg_error:nn {shmuel} {More than two arguments for {\backslash}Id}

\end{document}

I updated the code to reflect comments and modified it to support two similar commands, \Id and \ID, differing only in the case of the text they generate. However, I have been unable to get a backslash in the message text without also getting extraneous text.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse} % loads expl3
%See interface3.pdf

\ExplSyntaxOn

\NewDocumentCommand \Id {O{}}
  {
     \Id:nn {Id} {#1}
  }

\NewDocumentCommand \ID {O{}}
  {
     \Id:nn {ID} {#1}
  }

\cs_new:Npn \Id:nn #1 #2
  {
    \clist_set:Nn \l_tmpa_clist {#2}
    \int_case:nnF
      {\clist_count:N \l_tmpa_clist}
      {
        {0}q
        {
         \operatorname{#1}
        }
        {1}
        {
         \operatorname{#1} \sb {#2}
        }
        {2}
        {
         \operatorname{#1}
           \sp {\clist_item:Nn \l_tmpa_clist 1}
           \sb {\clist_item:Nn \l_tmpa_clist 2}
        }
      }
      {
         \msg_error:nnnn {shmuel} {toomany} {two} {#1: [#2]}
      }
  }

\msg_new:nnn {shmuel} {short} {#1}
\msg_new:nnnn {shmuel} {long} {#1} {#2}
\msg_new:nnnn
  {shmuel}
  {toomany}
  {More \ than \ #1  \ items \ for \ \string\\#2}
  %                                  {\textbackslash}#2?

\ExplSyntaxOff

\begin{document}

Test \ $\Id$, \  $\Id[A]$ \  and \  $\Id[{A,B}]$ \ inline.
\begin{equation}
  \text{Test} \ \Id, \\
   \Id[A], \\
   \Id[{A,B}]
\end{equation}

Test $\Id[{too},{many},{parms}]$

\end{document}
2

This was answered in the answer to the previous question, although the error highlighte in that question was in a different part of the code. You do not want \backslash here which is causing the error, this is a version using #1 in the error message to show the over-long list. note that \msg_error should just refer to the message by module and name, not the text.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse} % loads expl3
%See interface3.pdf

\ExplSyntaxOn

\NewDocumentCommand \Id {O{}}
  {
     \Id:n {#1}
  }

\cs_new:Npn \Id:n #1
  {
    \clist_set:Nn \l_tmpa_clist {#1}
    \int_case:nnTF
      {\clist_count:N \l_tmpa_clist}
      {
        {0}
        {
          \mathop{\mathrm{Id}}
        }
        {1}
        {
          \mathop{\mathrm{Id}}\sb{#1}
        }
        {2}
        {
          \mathop{\mathrm{Id}}
            \sp{\clist_item:Nn \l_tmpa_clist 1}
            \sb{\clist_item:Nn \l_tmpa_clist 2}
        }
      }
      {}
      {
          \msg_error:nnn {shmuel}{long} {#1}
      }
  }

\begin{document}

\ExplSyntaxOn
\msg_new:nnnn {shmuel} {long} {more\ than\ two\ arguments\ for\ \string\Id:\ #1} {help}
\ExplSyntaxOff

Test $\Id$, $\Id[A]$ and $\Id[A,B]$ $\Id[{too},{many},{parms}] $ inline.
\begin{equation}
  Test \Id, \\
   \Id[A], \\
   \Id[A,B]
\end{equation}

\end{document}
  • Why is it an error to use \backspace? Why does \msg_new:nnnn {shmuel} {toomany} {More \ than \ #1 \ items \ for \ #2} followed by \msg_error:nnnn {shmuel} {toomany} {two} {\string\\#1: [#2]} give ! Package shmuel Error: More than two items for \string (shmuel) \\Id:[{too},{many},{parms}] instead of ! Package shmuel Error: More than two items for (shmuel) \Id:[{too},{many},{parms}]? Should I edit my question to show the complete code? – shmuel Jun 20 at 20:28
  • @shmuel \backslash is a math command to make a \ operator it doesn't make a literal \ in a message the code in this answer produces a message of ! Package shmuel Error: more than two arguments for \Id:{too},{many},{parms} don't change it back to the wrong version. the text should be in the \msg_new as I show not the \msg_error – David Carlisle Jun 20 at 20:47
  • The fixed text is in the \msg_new. What I have is essentially the same error message for two outer (interface) macros, \Id and \ID, using a common expl3 subroutine. Should I use {textbackslash}#1, and is that valid in Math mode? – shmuel Jun 20 at 20:57
  • @shmuel I guess you want \msg_error:nnnn {shmuel} {toomany} {two} {#1: [#2]} – David Carlisle Jun 20 at 21:22
  • Does that men that there's no way to get a backslash in the error message? – shmuel Jun 20 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.