如何为列表代码添加字符串格式?

如何为列表代码添加字符串格式?

"file"我如何确保像下面(第 7 行) 的字符串类代码获得与下面的字符串相同的格式(紫色/muave)?在此处输入图片描述

\documentclass{article}
\usepackage{verbatim}       % code
\usepackage{listings}       % code
\usepackage{xcolor}         % color
\usepackage{color}          % bgrnd

\definecolor{light-gray}{gray}{0.95} 
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=Matlab,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  identifierstyle=\color{black},
  basicstyle={\small\ttfamily},
  numbers=left,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}


\begin{document}

\lstset{language=Matlab,
    morekeywords={matlab2tikz},
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    numbers=left, 
    numberstyle={\tiny \color{black}},
    numbersep=9pt,
    emph=[1]{for,end,break},emphstyle=[1]\color{blue},
}

\begin{lstlisting}[backgroundcolor=\color{light-gray},deletekeywords={and,using,new}]
disp('Starting')

variable = 5;
x = linspace(40000,140000,variable); % motor
    
for k = 1:x 
    sim("file")
    a = b(end); % comment 
end

%% comment
disp('Finished!')
\end{lstlisting}


\end{document}

答案1

我通过添加解决了这个问题morestring=*[d]{"}。希望这对某人有帮助。

相关内容