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.

Consider the following minimal example:



    % Q1: How can I use argument #1 without the backslash in the following line?
        description={\nopostdesc #3}, 

    % Q2: Why is the space between the '}' necessary?
    \def#1{\ensuremath{#2} } 

\NewS{\power}{P}{the power of something}{power}

    One can refer to the symbol via \power and \gls{symb:power} and. 

The two questions I have are already inserted in the example. In particular I am searching for a way to remove the backlash of the string \power which I pass as a first argument to the newcommand so that I can write something like:


And secondly I don't understand why I have to leave a space between the two braces in the \def in order to get "P and" in the output and not "Pand" - which is what I get when I remove the space. If I directly write \ensuremath{P} and I don't see any problems so I am just curious.

Thanks for your help!


share|improve this question

3 Answers 3

up vote 6 down vote accepted

It depends on how you need to use the control sequence name. A method for printing the control sequence name without the backslash is


In a definition, the explicit \power will be #1. But, again, it depends on what you want to do with the string.

The second question is a very frequently asked one: TeX ignores spaces after control sequence names like \power. Don't put a space in the definition, but rather write \power{} in the document.

If you just want to spare an argument, then use the LaTeX kernel function

        description={\nopostdesc #3}, 

Now \NewS{power}{P}{the power of something} will suffice and you will be able to say

One can refer to the symbol via \power{} and \gls{symb:power} and. 
share|improve this answer
Thanks for answering the second question! –  Christian Jun 11 '11 at 11:54
Regarding the second question: I thought that \power is treated like a string when I use it as an argument of a command, e.g. in \NewS{\power}{...} above and that I can access this string via #1 in the definition of the command \NewS. Thus I understand \def#1{something} as \def\power{something}. I was therefore looking for a way to use the string without the backslash in the line \newglossaryentry{symb:<insert string 'power' here>}{. But I think that Ians answer is the better way to go. –  Christian Jun 11 '11 at 12:01
To avoid the {} everytime you use \power, you could include the {xspace} package, add \xspace to the end of the defintition of \power, and then use it as The \power is the \power. and should have a space before the is but not before the period. –  Peter Grill Jun 11 '11 at 17:26
Another option (which is slightly shorter and I think better because it doesn't look like it is passing an empty argument to a macro) is to use \ —that is, a backslash followed by a space (or new line)— after \power: ...via \power\ and .... –  TH. Jun 12 '11 at 10:19

In expl3, there is a \cs_to_str:N function to get the macro name without a backslash. If you are not familar with expl3 syntax, you can define a clone of the function:

% We obtain: foobar

Note: \cs_to_str:N is fully expandable. Thus it's robust enough.

It's nontrivial to define a command like \cs_to_str:N. You can check the definition in source3 document, if you want to pry.

Here is my version of \cstostr:


The definition is much simpler than LaTeX3's \cs_to_str:N, but may fail when \escapechar is unusual. It is also fully expandable.

TeX ignores all spaces after a all-letter macro by default. To solve the question about space, you can use:

\power\ and


\power{} and
share|improve this answer
Thank you for your answer! –  Christian Jun 11 '11 at 13:31

An alternative approach is to create the macro from the string.

share|improve this answer
Thanks, this works. And it seems to be the more natural approach. –  Christian Jun 11 '11 at 11:45

Your Answer


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.