2

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 \"

  • 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
4

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}
  • @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
4

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.