Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...

share|improve this question

1 Answer 1

up vote 6 down vote accepted

\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

share|improve this answer
2  
Which will insert spaces after control sequences, of course. –  Joseph Wright Aug 29 '12 at 10:59
    
@JosephWright As does \show and such, so it's a feature :-) A more elegant solution probably requires verbatim style trickery. –  Stephan Lehmke Aug 29 '12 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 Aug 29 '12 at 11:06
    
@JosephWright ...in which case you'd get the complementary problem with spaces... –  Stephan Lehmke Aug 29 '12 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 Aug 29 '12 at 11:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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