アンダースコアのエスケープ

アンダースコアのエスケープ

内のテキストの一部を色付けしたいですlstlisting。次に例を示します。

\begin{lstlisting}[basicstyle=\linespread{0.8}\footnotesize\ttfamily, language=tcl, escapeinside={<@}{@>}]
  set_param drc.disableLUTOverUtilError 1
} {

      <@\textcolor{red}{              

      red\_text \\

      set\_property PACKAGE\_PIN V20 [get\_ports {red[0]}]

      }@>

\end{lstlisting}

\textcolor\アンダースコアは、その前に を使用せずに使用することはできません。 使用したいアンダースコアが数十個あり\textcolor、アンダースコアごとに追加したくありません\。 これを取り除く方法はありますか?

答え1

おそらくあなたはむしろデリミタLaTeXに逃げるよりも:

\documentclass{article}
\usepackage{listings,xcolor}

\lstdefinestyle{mystyle}{
  basicstyle = \linespread{0.8}\footnotesize\ttfamily,
  language   = tcl,
  moredelim  = [is][\color{red}]{<@}{@>}
}

\begin{document}

\begin{lstlisting}[style=mystyle]
set_param drc.disableLUTOverUtilError 1
}{
  <@red_text \\
  set_property PACKAGE_PIN V20 [get_ports {red[0]}] @>
}
\end{lstlisting}

\end{document}

ここに画像の説明を入力してください

関連情報