Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.