转义字符在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}