3

I'm trying to write a command to insert a boxed listing that break across pages. To this goal I'm trying to use minted for prettyprinting the listing and tcolorbox for creating the boxes (but I've also tried mdframed with the same result).

My problem is that the code breaks across pages/columns but it always starts at the beginning of a new page/column leaving a large empty space.

This is a MWE illustrating my attempt:

\begin{filecontents*}{/tmp/sex.ada}
-- Sex : implements sex.

with TEXT_IO; use TEXT_IO;

Package Sex is
   Type Sex is ( M, F, X );
   Function EqSex( A, B : in Sex ) return Boolean;
   Function Male( A : in Sex ) return Boolean;
   Function Female( A : in Sex ) return Boolean;
   Function Unknown( A : in Sex ) return Boolean;
   Procedure ReadSex( A : out Sex );
   Procedure WriteSex( A : in Sex );
End Sex;

Package body Sex is

  Function EqSex( A, B : in Sex ) return Boolean is
  Begin
     Return A = B;
  End EqSex;

  Function Male( A : in Sex ) return Boolean is
  Begin
     Return A = M;
  End Male;

  Function Female( A : in Sex ) return Boolean is
  Begin
    Return A = F;
  End Female;

  Function Unknown( A : in Sex ) return Boolean is
  Begin
    Return A = X;
  End Unknown;

  Procedure ReadSex( A : out Sex ) is
     ch : Character;
  Begin
     Get( ch );
     Case ch is
        when 'F'    => A := F;
        when 'M'    => A := M;
        when Others => A := X;
     End Case;
  End ReadSex;

  Procedure WriteSex( A : in Sex ) is
  Begin
     Case A is
        when F      => Put( 'F' );
        when M      => Put( 'M' );
        when X      => Put( 'X' );
        when Others => Null;
     End Case;
  End WriteSex;

End Sex;
\end{filecontents*}
\documentclass[DIV=16, paper=a4, fontsize=8pt]{scrartcl}
\RequirePackage[cachedir=.\jobname-cache]{minted}

\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage[english]{babel}
\RequirePackage[scaled=.8]{beramono}
\RequirePackage{tcolorbox}
\tcbuselibrary{skins,breakable,minted}

\newcommand{\showlongcode}[5][\linewidth]{%
   \begin{tcolorbox}[capture=minipage,breakable=true,colback={#2},colframe={#3},
          left=1pt,right=1pt,top=1pt,bottom=1pt,arc=0pt,outer arc=0pt,width=#1]
      \inputminted{#4}{#5}%
   \end{tcolorbox}%
}

\setminted{fontfamily=tt,fontsize=\footnotesize,encoding=utf8,escapeinside=``,style=trac}
\newcommand{\showlongada}[2][\linewidth]{\showlongcode[#1]{white!50}{black!150}{ada}{#2}}

\pagestyle{plain}
\pagenumbering{arabic}

\usepackage{multicol}

\begin{document}

\begin{multicols}{2}
\noindent\showlongada{/tmp/sex.ada}%

\noindent\showlongada{/tmp/sex.ada}%

\noindent\showlongada{/tmp/sex.ada}%

\end{multicols}
\end{document} 

I'm using multicol because this makes the problem more evident but I've the issue also in a single column document. The problem is that the output of the second \showlongada didn't starts immediately after the end of the first occurrence and breaking on the second column (the same is for the third call). This is not a problem of breaking the code since if I use a piece of code longer than one column this spans correctly on several columns but just it doesn't fill the current column.

I've tried to write the showlongcode by using mdframed with the same issue. This is the code I used:

\newcommand{\showlongcode}[5][\linewidth]{%
    \begin{mdframed[userdefinedwidth=#1,
        innerleftmargin=3pt,innerrightmargin=3pt,%
        innertopmargin=0.5pt,innerbottommargin=0pt,%
        backgroundcolor{#2},nobreak=false,%
        linecolor=#3, linewidth=1pt]%
        \inputminted{#4}{code/#5}%
    \end{mdframed}%
}

This is what I get (click here) What am I doing wrong?

Jack

  • This picture (click here) shows the output I get: I see nothing strange. – egreg Jun 17 '18 at 8:47
  • How is that possible? I don't get that but (how do you add a pic in a comment?) the two tcolorbox in separate columns. Could it due to different packages versions? This is my current configuration: minted 2017/09/03 v2.5.1dev, tcolorbox 2017/02/24 version 4.02 and multicol 2016/04/07 v1.8p. I'm still on texlive 2016. – Jack Jun 17 '18 at 16:29
  • Update your TeX distribution. You can easily add the picture to the question. – egreg Jun 17 '18 at 16:45
  • added the pic I will try to update the packages and I will be back. – Jack Jun 17 '18 at 18:16
2

This happens if I compile the test code with TeX Live 2016:

tcolorbox 2017/02/24 version 4.02 text color boxes
minted 2016/10/31 v2.4.1 Yet another Pygments shim for LaTeX

Doesn't happen with TeX Live 2017

tcolorbox 2018/01/12 version 4.12 text color boxes
minted 2017/07/19 v2.5 Yet another Pygments shim for LaTeX

or TeX Live 2018

tcolorbox 2018/03/22 version 4.13 text color boxes
minted 2017/07/19 v2.5 Yet another Pygments shim for LaTeX

enter image description here

  • You are right. I update tcolorbox to version 4.13 and it has worked like a charm. Thank you. – Jack Jun 17 '18 at 22:12

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.