4

I am using pandoc to convert Markdown to Tex, pandoc will render code blocks to \begin{verbatim}CODE\end{verbatim}, and fvextra only works with \begin{Verbatim}[breaklines].

How can I make {verbatim} to work as {Verbatim}[breaklines] ?

3

Redefine verbatim to use fancyvrb and fvextra options.

\documentclass{article}
\usepackage{fvextra}

\RecustomVerbatimEnvironment{verbatim}{Verbatim}{breaklines}

\begin{document}

\begin{verbatim}
la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$
la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$
la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$
\end{verbatim}

\end{document}
5

Here is how to do it on LaTeX side:

\documentclass{article}
\usepackage{fvextra}

\renewenvironment{verbatim}{%
  \VerbatimEnvironment
  \begin{Verbatim}[breaklines]%
}{%
  \end{Verbatim}%
}

\begin{document}
\begin{verbatim}
la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$
la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$
la$ la$ la$ la$ la$ la$ la$ la$ la$ la$ la$
\end{verbatim}
\end{document}

You only need to instruct pandoc to add these lines to preamble:

\renewenvironment{verbatim}{%
  \VerbatimEnvironment
  \begin{Verbatim}[breaklines]%
}{%
  \end{Verbatim}%
}

enter image description here

  • @Galaxy my code had some unneeded complication, I have simplified it. – user4686 Jan 10 at 8:43

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.