4

In the language I am defining in listings, text put inside {* and *} is commented out. I tried to implement this as morecomment = [s]{{*}{*}}, but understandably LaTeX gets the nesting confused. The result is that text placed between two * is commented out.

1 Answer 1

6

{* must be written as \{*, the same holds for *}: *\}.

The same escaping mechanism must be used for #, % and \ itself, i.e. \#, \% and \\. (This is actually stated multiple times in the listings.pdf manual)

I've 'misused' the Gnuplot language to define as additional comments {*...*}

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

\lstset{language=Gnuplot,morecomment = [s]{\{*}{*\}},commentstyle={\bfseries \color{blue}}}


\begin{document}
\begin{lstlisting}
  # A gnuplot comment
  plot sin(x) lt 2
  {* *}
\end{lstlisting}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .