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] ?

2 Answers 2

6

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}
7

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

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

You must log in to answer this question.

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