1

I am using matlab-pretifier to add some Matlab code to an appendix, and I would like to replace the units [g/cm^3] in the matlab code by $\mathrm{\left[g \cdot {cm}^{-3}\right]}$. For that I use the literate option under \lstinputlisting. However, literate does not seem capable of reading the square brackets. I would appreciate some help to solve this..............

Here a MWE:

\documentclass{article}

\usepackage[cp1252]{inputenc} \usepackage[T1]{fontenc} \usepackage[framed,numbered]{matlab-prettifier}

\begin{document}

\lstset{ language=Matlab, style=Matlab-editor, basicstyle=\mlttfamily\footnotesize, literate= {°}{\textdegree{}}1 {ö}{{"o}}1 {é}{{'e}}1 {[g/cm^3]}{{$\mathrm{\left[g \cdot {cm}^{-3}\right]}$}}7 }

\lstinputlisting[]{matlab_code.m}

\end{document}

... and here the .m code:

% ----------------------------
% Rö and Mé (T = 23°C); Mass density [g/cm^3]
var_1 = 10;
  • Do you really want cp1252? – egreg Oct 12 '20 at 07:40
  • yes. With my current matlab version I can't save files with utf8 encoding. For some reason I cannot recall right now, cp1252 works a bit better for me than latin1, and this is why I'm using cp1252. – Euclides Oct 12 '20 at 08:56

0 Answers0