I want to colorize a part of text within lstlisting. Here is an example:

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


      red\_text \\

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



\textcolor does not allow to use underscore without using \ in front of it. There are tens of underscores that I want use within \textcolor and I don't want to add \ for each underscore. Is there a way to get rid of this?


You probably rather want a delimiter than to escape to LaTeX:


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


set_param drc.disableLUTOverUtilError 1
  <@red_text \\
  set_property PACKAGE_PIN V20 [get_ports {red[0]}] @>


enter image description here

  • Maybe something like moredelim = [is][\color{red}]{<RED}{RED>} or moredelim = [is][\color{red}]{<EMPH}{EMPH>} would be a better choice than {<@}{@>} – cgnieder Jan 31 '17 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.