如何在 \lstinline 中转为 LaTeX?

如何在 \lstinline 中转为 LaTeX?

转义字符在lstlisting环境内部有效,但在内部无效\lstinline

在此处输入图片描述

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

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

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

\usepackage{listings}
\usepackage{matlab-prettifier}
% BEGIN_FOLD

\lstdefinestyle{matlab-inline}{
    style=Matlab-editor, 
    basicstyle=\linespread{0.8}\mlttfamily\color{DodgerBlue3},
    escapechar=",
}

% END_FOLD

\lstset{style=matlab-inline}

\begin{document}

\begin{frame}[fragile, environment=frame]

    \begin{lstlisting}
    text "$e = m c^{2}$"
    \end{lstlisting}
    
    \lstinline|text "$e = m c^{2}$"|

\end{frame}

\end{document}

答案1

恕我直言,\lstinline它不支持转义字符,因为您可以在任何您想要的地方结束内联代码,然后在 LaTeX 代码之后重新启动它。

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

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

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

\usepackage{listings}
\usepackage{matlab-prettifier}
% BEGIN_FOLD

\lstdefinestyle{matlab-inline}{
    style=Matlab-editor, 
    basicstyle=\linespread{0.8}\mlttfamily\color{DodgerBlue3},
    escapechar=",
}

% END_FOLD

\lstset{style=matlab-inline}

\begin{document}

\begin{frame}[fragile, environment=frame]

    \begin{lstlisting}
    text "$e = m c^{2}$"
    \end{lstlisting}
    
    \lstinline|text |$\mathcolor{DodgerBlue3}{e = m c^{2}}$

\end{frame}

\end{document}

在此处输入图片描述

相关内容