Assuming that I have already parsed some text verbatim, using an xparse +v
argument, what is the best way to typeset the text in a way that respects the original formatting?
Note that I cannot directly typeset the text using a verbatim
environment, as I need to gently preprocess the text beforehand.
I have looked at how the verbatim
environment set up typesetting, though it’s not clear what parts are doing what things, and I was wondering if there were a “modern” approach using currently-available LaTeX3 tools.
Addendum: After the text is parsed with with the +v
argument, it is processed by some regexes, then it is split on the endline character and stored in a sequence variable as a set of lines, so that it can be written to an external file, before typesetting.
Example code:
\NewDocumentCommand \myverb { +v }
{ \kelly_verb:n { #1 } }
\tl_new:N \l__kelly_verb_body_tl
\seq_new:N \l__kelly_verb_lines_seq
\cs_new_protected:Nn \kelly_verb:n
{
\tl_set:Nn \l__kelly_verb_body_tl { #1 }
\regex_replace_all:NnN \c__kelly_verb_regex { <replacement> }
\l__kelly_verb_body_tl
\kelly_set_split_lines:NV \l__kelly_verb_lines_seq
\l__kelly_verb_body_tl
\seq_map_inline:Nn \l__kelly_verb_lines_seq
{ \iow_now:Nn \g__kelly_output_iow { ##1 } }
% Typeset here...
}
\char_generate:nn {13} {12}
) into something that really breaks lines. Also you'll have to use\verbatim@font
and have to suppress ligatures (you can't use\@noligs
as that needs to turn characters active, so maybe via\tl_replace_all:Nnn
for the characters you know to form ligatures, take a look at the\verbatim@nolig@list
).