2
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\begin{document}
\tl_to_str:n { testing _ things }

\par

\tl_set:Nn \l_tmpa_tl { testing _ things }
\tl_to_str:N \l_tmpa_tl
\end{document}

gives a strange result (testing ̇things). How can I get testing_things? I basically want verbatim content (with line breaking).

2
  • 2
    This has nothing to do with expl3, but with the fact that OT1 encoded fonts don't have _ in the ASCII slot for it (and miss several other characters). Do \usepackage[T1]{fontenc}. However, \tl_to_str:n will always add a space after control sequence names (when made of letters) and double #.
    – egreg
    Commented Sep 30, 2014 at 14:53
  • 2
    If you just want to grab verbatim, \NewDocumentCommand\myverb{v}{\texttt{#1}} will do it, with as @egreg says \usepackage[T1]{fontenc} to deal with awkward chars.
    – Joseph Wright
    Commented Sep 30, 2014 at 15:54

1 Answer 1

4

This is by no means strange: if I try the simple example

\documentclass{article}
\begin{document}
A\char`\_B
\end{document}

I get

enter image description here

because the standard fonts in OT1 encoding have the dot accent in the slot ASCII reserves for the underscore. Just adding

\usepackage[T1]{fontenc}

produces

enter image description here

because T1 encoded fonts have all the ASCII characters in their proper place.

The function \tl_to_str:n is not meant for verbatim, but for transforming input into a string consisting of category code 12 characters (spaces are still category code 10); it uses the same mechanism TeX uses for \string, in particular a space will be added after control words, so

\tl_to_str:n {\foo\baz?}

will print

\foo \baz ?

Moreover, # characters will be doubled.

You can use it as a “poor person's verbatim”, if you're aware of these limitations:

\texttt{\tl_to_str:n{some_verbatim}}

will print

some_verbatim

also when the default encoding is OT1.

You must log in to answer this question.

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