0

I want to produce MATLAB prettified code with MATLAB code. Using .\ causes error. alsoletter={.\\} in \lstdefinestyle does not seem to work

\documentclass[aspectratio=169, xcolor={x11names}, t, handout]{beamer}

\usepackage{calc}

\usetheme{Dresden}
\usefonttheme{professionalfonts}
\renewcommand{\sfdefault}{ppl}

\usepackage[T1]{fontenc}
\renewcommand{\encodingdefault}{T1}

\usepackage{listings}

% ========== MATLAB codes packages =========
% BEGIN_FOLD

\usepackage[]{matlab-prettifier}
% BEGIN_FOLD

% Inline code
% BEGIN_FOLD

\lstdefinestyle{matlab}{
    % style
    style=Matlab-editor,
    basicstyle=\linespread{0.8}\mlttfamily\footnotesize,
%   alsoletter={.\\},
    literate=
    *{.\\}{\textcolor{IndianRed1}{. \textbackslash{}}}{1}, % .\
}

\lstset{style=matlab}

% END_FOLD

% END_FOLD

% END_FOLD

\begin{document}

\begin{frame}[fragile, environment=frame, allowframebreaks=0.99]
    
\begin{lstlisting}
a.\b
\end{lstlisting}
    
\end{frame}

\end{document}

1 Answer 1

3

You shouldn't use beamer for your minimal examples if this is not needed. It is a nuisance to have to load all the pgf stuff.

Beside this: listings has a documentation, and this documentation describes quite clearly the syntax of literate and also says that you need additional braces to protect commands in the content.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage[]{matlab-prettifier}

\lstdefinestyle{matlab}{
    style=Matlab-editor,
    basicstyle=\linespread{0.8}\mlttfamily\footnotesize,
    literate=
    *{.\\}{{\textcolor{red}{.\textbackslash{}}}}{2}, % .\
}

\lstset{style=matlab}

\begin{document}

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

enter image description here

1

You must log in to answer this question.

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