Consider the following LaTeX document:
\documentclass{article}
\usepackage{fancyvrb}
\DefineVerbatimEnvironment{example}{Verbatim}{commandchars=\\\{\}}
\begin{document}
\begin{example}
Foo\\{}Bar
Foo\linebreak{}Bar
\end{example}
\end{document}
I would expect the \\
and \linebreak
commands to produce a line break each, so the typeset output ought to look like
Foo
Bar
Foo
Bar
However, the actual output is
Foo Bar
FooBar
How do I produce an explicit line break inside a fancyvrb-based verbatim environment?
(Incidentally »Just hit Return« isn't the answer I'm looking for. I have lots of text based on the alltt environment which contains markup like
Foo\nextline Bar
I use this to introduce »typographic« line breaks in shell command output, where there is no actual line break in the output but I need to start a new line because there is no more room on the current line. In my document, these »typographic« line breaks can be distinguished from genuine line breaks because there is a special symbol before/after the line break, along the lines of
\newcommand{\nextline}{\ensuremath{\rhd}\linebreak\ensuremath{\lhd}}
I'd much rather not change a couple thousand pages' worth of documentation.)
listings
instead of (or together with)fancyvrb
be acceptable? If this is the caso, you van keep your current environment in the doucment body and simply define it differently in your preamble; something like\documentclass{article} \usepackage{listings} \lstset{% basicstyle=\ttfamily, breaklines=true, columns=fullflexible, escapeinside = ||, breakindent=0pt, } \lstnewenvironment{example}{}{} \begin{document} \begin{lstlisting} Foo|\\|Bar \end{lstlisting} \end{document}
fancyvrb
typesets each line in a\hbox
. Thelistings
package allows for line breaks and even provides hooks for symbols at end and start of broken lines.