我想對 中的部分文字進行著色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}