1

I am trying to insert a Maltab code in a Latex document using Matlab-Prettifier. I am configuring the package as indicated below:

\usepackage[framed]{matlab-prettifier}

\lstset{
  style              = Matlab-editor,
  basicstyle         =\ttfamily\scriptsize,
  escapechar         = ",
  literate           = {~} {$\smallsim$}{1},
  mlshowsectionrules = true,
}

However, after Latex compilation, in the first use of the line-continuation (...) in the Matlab code, it appears characters that are not in the original code, as indicated in the figure below by 'b@x':

enter image description here

No warning is generated after compilation.

When I remove the Chapterbib package, this does not occur anymore. Chapterbib is being used without any special configuration.

Does anyone know what I can do to correct such a problem?

Here, I include a basic Latex document that produces the same problem I described above:

\documentclass{book}

\usepackage{chapterbib} 

\usepackage[framed]{matlab-prettifier}

\lstset{
  style              = Matlab-editor,
  basicstyle         =\ttfamily\scriptsize,
  escapechar         = ",
  mlshowsectionrules = true,
}

\begin{document}

\begin{lstlisting}
...
\end{lstlisting}

\end{document}

1 Answer 1

1

This looks like a bug in listings, revealed in specific circumstances, but I don't know enough to make the MWE without matlab-prettifier, and the three dots (which are special syntax for matlab). The problem is that listings (in \lst@CalcLostSpaceAndOutput) outputs the contents of the scratch box \@tempboxa, perhaps without having set it anywhere, or set it only in a local group.

Demonstration

\documentclass{book}
\usepackage{matlab-prettifier}
\lstset{
  style = Matlab-editor,
}

\makeatletter \setbox\@tempboxa\hbox{oops!}\makeatother

\begin{document}

\begin{lstlisting}
...
\end{lstlisting}
\end{document}

As a work-around insert

\makeatletter \setbox\@tempboxa\hbox{}\makeatother

in the document, at least at the beginning, but potentially in more places.

3
  • 1
    Thanks for your reply. I inserted "\makeatletter \setbox\@tempboxa\hbox{}\makeatother" in the document and the problem was solved! May 11, 2020 at 19:46
  • Hurrah. Had exactly the same issue. This does indeed fix it. Placed the workaround command at the start of my appendix where I've got the code located. Jul 7, 2020 at 15:24
  • By the way, chapterbib has been updated to not leave anything in \@tempboxa. Jun 10, 2021 at 7:45

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.