I have a macro which uses \typeout to print messages. I would like to unescape these.


Then \mymessage{foo\#bar} should print foo#bar. Right now it prints foo\#bar.


Answers below show how to solve the specific problem of unescaping \# character. However, this was meant as an example only. I also need to unescape \% and any other such combination.

  • “Any other” is a bit too generic; can you make a list? Anyway, you asked for \#.
    – egreg
    Nov 7, 2015 at 10:40
  • What I really want to do is to typeout url's which are passed to a latex command, such that they are without any escapes.
    – highsciguy
    Nov 7, 2015 at 10:50

2 Answers 2


Edit to follow up on OP's modifications.

Perhaps this will be ok with your yet to be precisely specified yet unknown constraints:

\newcommand{\mymessage}[1]{\bgroup\escapechar-1 \typeout{\detokenize{#1}}\egroup}





original answer

If you are not using \mymessage from inside macros, you could try

                        \catcode92 13 \mynoescapemessage}





Notice that the reason the thing is a bit complicated (I could have chosen catcode 9 (aka "ignore")) is to avoid:


due to special treatment by TeX of # tokens.


Redefine \# (locally):



The output is


Be careful with protecting end-of-lines in your macro definitions.

Here is how you can add escape codes:


  \let\%\@percentchar % already provided by LaTeX


Also note that balanced braces need not be escaped in a \typeout.

The output is

  • Please see my edit.
    – highsciguy
    Nov 7, 2015 at 10:27

You must log in to answer this question.

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