2

I could not make a smaller MWE than the following. I noticed at random places in the document, the listing comes out corrputed, then it becomes ok for a while, then it goes bad.

I am basically using tcolorbox with listing to format lots of small code fragments. Using the same code to generate the listing, some random listings show corruption in the PDF file. Either lines missing, or some text blacked out, or some half showing, or some black bars show up.

Here is typical output

Mathematica graphics

Few copies later, it can change size

Mathematica graphics

sometimes the listing shows up with black bars at random places

Mathematica graphics

I used below one example code fragment which generates one listing. I tried to find a way to automate duplicating this to make it small MWE but could not, since it has Verbatim in it. So I had to manually make about 10 or so copies for the problem to show up.

There is no compile error. Just the PDF comes up with these bad listings.

I think I will removing tcolorbox and go back to basic listings use. Too many problems that I can't figure myself. Sorry again for the long MWE. It is actually the same code (one tabular with 2 cells) one cell is the listing, the next one is small Verbatim text. But again, I do not know how to make a loop to duplicate this. If you do not like to copy all this code by hand, I put this code below, and the PDF file it generated on my Linux box in this folder on my site

\begin{filecontents*}{\jobname.txt}
clear all;
s   = tf('s');
sys = ( s+1 )/(s^2  + s  +  1);
[num,den]=tfdata(sys,'v');
%convert to state space
[A,B,C,D] = tf2ss(num,den)
\end{filecontents*}

\documentclass[12pt]{scrbook}% 
\IfFileExists{luatex85.sty}
{
\usepackage{luatex85}
}
{}
\usepackage{longtable}
\usepackage{listings}
\usepackage{color}
\definecolor{bg}{RGB}{240,240,240}
\usepackage{upquote} %to fix string quotes
\usepackage[most]{tcolorbox}
\tcbuselibrary{listings}
\usepackage{matlab-prettifier}
\usepackage{amsmath}
\usepackage{fancyvrb}
\usepackage{pgffor}
\usepackage{fancyvrb}

\begin{document} 


\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}


\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}

\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}


\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}


\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}


\begin{tabular}[c]{|p{0.6\textwidth}|p{0.4\textwidth}|}\hline
\textbf {Matlab}\vspace {10pt} {\newboxarray {mylisting} 
\tcbinputlisting {nobeforeafter,enhanced,listing only,hbox, listing file={\jobname .txt}, size=small,
store to box array=mylisting,listing options={numbers=left, numberstyle=\scriptsize ,
basicstyle=\ttfamily \normalsize , breaklines = false,showspaces=false}} 
\boxarraygetwidth [mylisting]{\mylistingwidth }{1} 
\tcbinputlisting{nobeforeafter,enhanced,listing only, width=\mylistingwidth ,left skip=7pt, 
breakable,listing file={\jobname .txt},size=small, listing options={style=Matlab-editor,numbers=left, 
numberstyle=\scriptsize ,basicstyle=\ttfamily \normalsize ,
breaklines = false,escapechar=`,showspaces=false,mlshowsectionrules = true}} }
&
\begin{verbatim}
dfklajdflkjdsf
\end{verbatim}
\\ \hline
\end{tabular}
\end{document}

lualatex on TL 2016.

5
  • It would have been helpful to indicate in the code which of the listings fails instead of letting us to figure out :-(
    – user31729
    Commented Jun 25, 2016 at 12:46
  • @ChristianHupfer it is the same listing. Same copy. Just duplicated. if you compile it, you'll see the random one which fails. On the above, it is on third page. If you view the PDF. It is only 3 or 4 pages. As I said, I did not know how to make a loop to replicate it. So I copy-pasted same table 10 times. The last image I showed with the bars is from another file, which I did not include to make it small MWE.
    – Nasser
    Commented Jun 25, 2016 at 12:48
  • 1
    I think breakable is of no use here since the tcolorbox` can't break within a tabular cell, as far as I know, using it makes tcolorbox choke on it. Removing breakable from the boxes will provide what you expect, not the clutter. You should also define listing style to make the code easier to read
    – user31729
    Commented Jun 25, 2016 at 12:52
  • @ChristianHupfer it looks like you are correct. Thank you. breakable is what causes the corruption when used inside tabular. I still need to breakable for long listing so it can span pages, but will use it only when outside tabular. Listings inside tabular are for small fragments. Feel free to post this as answer. I just compiled my large file and I see no bad listing any more.
    – Nasser
    Commented Jun 25, 2016 at 13:11
  • I think I will write to Thomas Sturm about this.
    – user31729
    Commented Jun 25, 2016 at 13:28

1 Answer 1

5

breakable inside a tabular does not seem very healthy as the tcolorbox most likely can't break at all. The disrupted box breaks apparently in as much boxes as have been used before, which is either a bug or tcolorbox sums up some pagegoal.

2
  • 1
    You are right, inside a tabular environment a tcolorbox cannot be breakable. Well, one can use the option, but it will result into the clutter as seen above. It is the same as for breakable boxes inside another tcolorbox (but this is detected automatically). Commented Jun 27, 2016 at 10:05
  • @ThomasF.Sturm: Thanks for conformation -- I wanted to write a mail to you about this
    – user31729
    Commented Jun 27, 2016 at 11:08

You must log in to answer this question.

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