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

How can I assign an arbitrary string - that may include special characters or even macronames - to a variable just as it is? e.g. like this: \newcommand{\mystring}{\assignstring{abc{}\w'\macroname \\}} wich must results (at least as \meaning\mystring): "abc{}\w'\macroname \"

share|improve this question
Wouldn't \newcommand{\mystring}{abc{}\w'\macroname \\} do exactly that? Please try and be more precise on what you need. – egreg Apr 19 '12 at 8:30
up vote 3 down vote accepted

You can store an arbitrary string verbatim into a macro using either \verbdef (verbdef package) or \Verbdef (newsverb package).

The difference between both is that the first defines the macro including all font commands required to print the text in the document. The latter only stores the characters, so that they can also be printed to an auxiliary files, which wouldn't be possible with included font commands.



% In preamble or body
\verbdef\mystringprintable|abc{}\w'\macroname \\|
\Verbdef\mystringplain|abc{}\w'\macroname \\|

% To print:

share|improve this answer
@David Carlisle Yes, "verbatim", that was the world I did not find. Ok, any chance to accept two answers simultaneously? David answers - actually the same solution - was just as useful as Martin's, and they were delivered at the same time. I only accepted Martin's because it gave me a little bit more information. Thanks for both. – pmks Apr 19 '12 at 16:33

It's not clear what you mean (partly because of terminology, Tex doesn't have strings or variables) But I suspect that you want something like this


\verbdef\mystring|{abc{}\w'\macroname \\###|



share|improve this answer

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.