3

I can’t find a way to print the content of a LaTeX3 string and/or a text verbatim (or to be more precise, I found a solution by writing the content to a file and then displaying the verbatim content of that file but it looks really ugly):

enter image description here

\documentclass{article}
\ExplSyntaxOn

\NewDocumentCommand{\printMeVerbatim}{m}{
%% Don’t know what to put here: I managed to write it in a file to write its content verbatim,
%% but it sounds really dirty
#1
}

\ExplSyntaxOff

\begin{document}

I would like to print this string verbatim: ``\printMeVerbatim{Hello $\delta$.}'' like:
\begin{verbatim}
Hello $\delta$.
\end{verbatim}
ideally using LaTeX3 syntax.

\end{document}
4
  • 3
    not really a latex3 issue but ltcmd (xparse) I think you want v not m Aug 30 at 9:45
  • \NewDocumentCommand{\printMeVerbatim}{v}{{\fontencoding{T1}\ttfamily#1}} (T1-encoding just in case ... but better use it generally) Aug 30 at 9:47
  • But wait, I actually need to use this in a loop: \seq_map_inline:Nn \l_robExt_placeholders_seq {- ~ Placeholder ~ called ~ ``##1'' contains:} where ##1 can contain stuff like underscore. Is there a verbatim equivalent of \seq_map_inline?
    – tobiasBora
    Aug 30 at 9:48
  • See also How to handle verbatim material in LuaLaTeX?
    – Mico
    Aug 30 at 10:40

1 Answer 1

7

enter image description here

v is provided by ltcmd for this sort of use.

\documentclass{article}
\ExplSyntaxOn

\NewDocumentCommand{\printMeVerbatim}{v}{%%%%%
%% Don’t know what to put here: I managed to write it in a file to write its content verbatim,
%% but it sounds really dirty
\begin{flushleft}\ttfamily%
#1%%%%%
\end{flushleft}
}

\ExplSyntaxOff

\begin{document}

I would like to print this string verbatim: ``\printMeVerbatim{Hello $\delta$.}'' like:
\begin{verbatim}
Hello $\delta$.
\end{verbatim}
ideally using LaTeX3 syntax.

\end{document}
14
  • I did it as a display like verbatim as requested so the quotes are weirdly placed. You coulddo it inline as \texttt{#1} instead. Aug 30 at 9:51
  • Thanks, but in my actual problem, the string comes from a map: \seq_map_inline:Nn \l_robExt_placeholders_seq {- ~ Placeholder ~ called ~ ``##1'' contains:} where ##1 can contain for instance underscores that gets interpreted by latex. Any idea how to proceed in that case?
    – tobiasBora
    Aug 30 at 9:51
  • 3
    @tobiasBora apart from the fact it's almost completely different to your question:-) just use \detokenize{#1} (or \tl_to_str:n which is same thing) Aug 30 at 9:53
  • Awesome, thanks! (I can only accept it in 5mn)
    – tobiasBora
    Aug 30 at 9:54
  • I don’t know why, but sometimes my newlines are turned into \Omega when printed. I created a new question here tex.stackexchange.com/questions/694731/…
    – tobiasBora
    Aug 30 at 13:08

You must log in to answer this question.

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