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.

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

2 Answers 2

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.

\documentclass{article}
\usepackage{verbdef}
\usepackage{newsverb}

\begin{document}

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

% To print:
\mystringprintable
\texttt{\mystringplain}

\end{document}
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

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{verbdef}

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

\begin{document}

\mystring

\end{document}
share|improve this answer

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.