9

Is it possible to remove blank (empty) lines in minted, and gobble multiple blank lines to a specified amount, like the emptylines option in listings?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{minted}
\usepackage{listings}
% I want something like the emptylines option
\lstset{language=[Visual]{C++},emptylines=1}
\begin{document}
\begin{minted}[frame=single]{cpp}
int i = 0;


i++;
\end{minted}
\begin{lstlisting}
int i = 0;


i++;
\end{lstlisting}
\end{document}
  • Thanks Marco, it seems I have programmed to much C++ today. – Juri Robl Sep 29 '12 at 17:55
  • Af far I know you can globbe the star of lines or disable numbering of blank lines (numberblanklines=false) but wihout removing lines. – Fran Jul 7 '13 at 22:07
3

The minted package uses fancyvrb behind the scenes. This package doesn't have a build-in facility to skip blank lines. It is possible to add a test to skip blank lines, for example

\begingroup
\makeatletter
\catcode`\^^M=\active
\gdef\FancyVerbGetLine#1^^M{%
  \@nil
  \FV@CheckEnd{#1}%
  \ifx\@tempa\FV@EnvironName
    \ifx\@tempb\FV@@@CheckEnd\else\FV@BadEndError\fi
    \let\next\FV@EndScanning
  \else
    \def\FV@Line{#1}%
    \ifx\FV@Line\@empty % Test added here
      \def\next{\FV@GetLine}%
    \else
      \def\next{\FV@PreProcessLine\FV@GetLine}%
    \fi
  \fi
  \next}%
\endgroup

Dealing with picking particular numbers of blank lines is more tricky: Id be tempted to simply go for listings or edit the code source rather than try to alter this.

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.