TransWikia.com

Changing the pretty-printing of delimiters in a listings language

TeX - LaTeX Asked by IIM on May 11, 2021

In my listings language I have

commentstyle=color{red}

morecomment = [n][commentstyle]{(*}{*)}

So comments are written (* df *) in the tex file and they turn out like

example.

These thick, centred asterisks don’t look right for my language. I’d prefer them to turn out like text{a*b} would (where the asterisk is smaller and rises halfway up, exactly as it appears on StackExchange). I need to use asterisks outside of comments as well, and ideally I’d like to choose the style of those separately. I know I can change the style of asterisks by putting them in the literals, but that means my comments don’t work. So is it possible to change the style of comment-delimiters (without changing the input of the listings environment), and is it possible to independently change the style of literals which partially overlap with comment-(or other)-delimiters?

Here’s a MWE

documentclass{article}

usepackage{color}
usepackage{listings}

lstdefinelanguage{Isar}{
    stringstyle=color{black},
    commentstyle=color{red},
    moredelim = [s][stringstyle]{"}{"},
    morecomment = [n][commentstyle]{(*}{*)}, 
    literate=
                {<not>}{{$neg$}}1 
                {<times>}{{$×$}}1
  }[comments,strings]%
  
begin{document}

begin{lstlisting}[language=Isar]{}  
locale Line_Measure = Lines isLine
  "a*b" (*df*) 
end{lstlisting}

end{document}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP