4

While printing the List of Symbols, I would like, in a draft, to print the definition commands as well. For instance, consider the following commands:

\providecommand{\perm}{\ensuremath{\pi}}
\providecommand{\permel}[1]{\ensuremath{\perm(#1)}}

and the following command for printing symbols within a table:

\providecommand{\symbdef}[2]{\texttt{\color{blue}\string #1} & #1 & #2}

Now, the code:

\section{List of Symbols}
\begin{tabular}{lll}
\symbdef{\perm}{a permutaion} \\
\symbdef{\permel{i}}{the value of \perm for the argument $i$} \\
\end{tabular}

proudeces output: \perm and \permeli in the first column. However I would like to print \permel{i} instead of \permlei here and do not know how.

Please help...

1 Answer 1

6

\string only takes one token and prints that, so it only ever sees \permel.

Try

\providecommand{\symbdef}[2]{\texttt{\color{blue}\detokenize{#1}} & #1 & #2}

This will insert explicit spaces after control sequences, which is not semantically wrong, but might not be aesthetically pleasing. In that case, try filtering out the spaces like this:

\providecommand{\symbdef}[2]{\texttt{\color{blue}\expandafter\filterspaceaftercs\detokenize{#1\x}_} & #1 & #2}

\begingroup
\makeatletter
\catcode`\|=\z@
\catcode`\\=12
|gdef|filterspaceaftercs#1\#2 #3_%
{%
  #1%
  |ifx|empty#3|empty
    |expandafter|@gobble
   |else
    \#2|expandafter|filterspaceaftercs
  |fi
  #3_%
}
|endgroup

example

9
  • 2
    Which will insert spaces after control sequences, of course.
    – Joseph Wright
    Commented Aug 29, 2012 at 10:59
  • @JosephWright As does \show and such, so it's a feature :-) A more elegant solution probably requires verbatim style trickery. Commented Aug 29, 2012 at 11:05
  • Yes, I known :-) I was just contrasting it with \string, which does not but where you do need to do a token-by-token conversion (tricky, depending on requirements).
    – Joseph Wright
    Commented Aug 29, 2012 at 11:06
  • @JosephWright ...in which case you'd get the complementary problem with spaces... Commented Aug 29, 2012 at 11:08
  • 1
    I recoil with dismay and horror at this lamentable plague of macros which do not have expandable versions. — Charles Hermite :P
    – percusse
    Commented Aug 29, 2012 at 11:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .