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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to define a command \mydef that does something like this:



\def\foo{bar} \verb|\foo=bar|

The command:

\newcommand{\mydef}[1]{\def #1}

does the first bit, but I don't seem to be able to use verbatim in a command - how do I access the contents of #1? In this context I would be happy if I could just discard the first character...

share|improve this question
Welcome to tex.sx! A tip: If you indent lines by 4 spaces, then they are marked as a code sample. You can also highlight the code and click the "code" button (with "101010" on it). – lockstep Mar 26 '11 at 15:51
Could you explain the "In this context I would be happy if I could just discard the first character..." a little but more. The \ of \foo, or the b of bar? – Martin Scharrer Mar 26 '11 at 15:52
Does bar really be read verbatim or do you only want to display it so, but keep it normal for the definition of \foo? – Martin Scharrer Mar 26 '11 at 15:54
up vote 4 down vote accepted

You can use \string to print the command as string and \strip@prefix in combination with \meaning to display the macro content:





share|improve this answer
That's great! Thanks a lot! – Joseph Maher Mar 26 '11 at 16:12
+1, very elegant solution. – chl Mar 26 '11 at 16:58
@chl: Thanks. The \expandafter\strip@prefix\meaning is actually taken from \@onelevel@sanitize. – Martin Scharrer Mar 26 '11 at 17:00

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.