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
Few copies later, it can change size
sometimes the listing shows up with black bars at random places
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.
breakable
is of no use here since the tcolorbox` can't break within atabular
cell, as far as I know, using it makestcolorbox
choke on it. Removingbreakable
from the boxes will provide what you expect, not the clutter. You should also define listing style to make the code easier to readbreakable
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.