![アンダースコアのエスケープ](https://rvso.com/image/348626/%E3%82%A2%E3%83%B3%E3%83%80%E3%83%BC%E3%82%B9%E3%82%B3%E3%82%A2%E3%81%AE%E3%82%A8%E3%82%B9%E3%82%B1%E3%83%BC%E3%83%97.png)
内のテキストの一部を色付けしたいです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}