0

I want to customize the style of Matlab-editor in matlab-prettifier package. What I want is to produce background for MATLAB styled commands, but it does not seem that basicstyle key accepts commands with arguments

It is possible to get this by creating custom commands such as in

Different background colors for lstinline

However, I would rather use \lstinline command directly because I want TeXstudio to highlight verbatim code. This topic seems to contain what I want, but I need to adapt it for my specific needs

listings lstdefinestyle not work with custom defined command

This is the result I want

enter image description here

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

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

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

\usepackage{bigstrut}

\usepackage[]{matlab-prettifier}
% BEGIN_FOLD

\lstdefinestyle{matlab-inline}{
    % style
    style=Matlab-editor, % default style for matlab pretification
    basicstyle=\linespread{0.8}\mlttfamily\color{DodgerBlue3}, % font style and size
}

% END_FOLD

\usepackage{tikz}

\newcommand{\matlabinline}[1]
{%
    \begin{tikzpicture}[baseline]
        \node[fill=Ivory1, inner sep=0mm, outer sep=0mm,  inner xsep=0mm, inner ysep=1pt, opacity=0.75, anchor=base] (node) {\bigstrut#1};
    \end{tikzpicture}%
}

\begin{document}

\begin{frame}[fragile, environment=frame, allowframebreaks=0.99]
    
    \smash{\rlap{\vrule width 0.1pt depth 0em height 0.75em}}%
    \smash{\rlap{\rule{\linewidth}{0.1pt}}}%
    \matlabinline{\lstinline[style=matlab-inline]|plot(X1, Y1, LineSpec1)|} \lstinline[style=matlab-inline]|plot(X1, Y1, LineSpec1)|
    
\end{frame}

\end{document}
2
  • So if I understood correctly, you want the second inline \lstinline[style=matlab-inline]|plot(X1, Y1, LineSpec1)| to have the identical result as the first line \matlabinline{\lstinline[style=matlab-inline]|plot(X1, Y1, LineSpec1)|} ?
    – user202729
    Commented Jan 28, 2023 at 8:01
  • This is what I really want Commented Jan 28, 2023 at 8:13

1 Answer 1

0

As far as I can see there's no way to solve this without patching lstinline. It isn't really recommended to patch it, for your specific problem I think the alternative solution (changing syntax highlighting in TeXStudio) works as well -- see Making TeXstudio syntax highlighting recognize a custom verbatim environment , but if you insist there is this way:

%! TEX program = pdflatex

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

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

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

\usepackage{bigstrut}

\usepackage[]{matlab-prettifier}
% BEGIN_FOLD

\lstdefinestyle{matlab-inline}{
    % style
    style=Matlab-editor, % default style for matlab pretification
    basicstyle=\linespread{0.8}\mlttfamily\color{DodgerBlue3}, % font style and size
}

% END_FOLD

\usepackage{tikz}

\NewCommandCopy \oldlstinline \lstinline

\ExplSyntaxOn

\RenewDocumentCommand \lstinline {o v} {
    \begin{tikzpicture}[baseline]
        \node[fill=Ivory1, inner~sep=0mm, outer~sep=0mm,  inner~xsep=0mm, inner~ysep=1pt, opacity=0.75, anchor=base]
            (node) {\bigstrut \oldlstinline[#1]{#2}};
    \end{tikzpicture}
}
\ExplSyntaxOff

\fastrecompileendpreamble
\begin{document}

\begin{frame}[fragile, environment=frame, allowframebreaks=0.99]
    
    \smash{\rlap{\vrule width 0.1pt depth 0em height 0.75em}}%
    \smash{\rlap{\rule{\linewidth}{0.1pt}}}%

    \lstinline[style=matlab-inline]|plot(X1, Y1, LineSpec1)|
    
\end{frame}

\end{document}

It redefines lstinline the way described in the code.

You must log in to answer this question.

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