TransWikia.com

latex/listings extend/add to a literate rule

TeX - LaTeX Asked on July 22, 2021

I was looking at this question here Listings: syntax for literate but when I try the mew of the solution, it crashes if I insert special characters like the German ä.

Since these should be escaped by the first literate rule, I assume that the first literate rule is overwritten by the following one.

Is there a way around this? (then it’s be possible to specify a literate rule in general for all listings and then just adding to to the literate rule some things for each language)

One Answer

There must be some clever way just to add to the literate list, but I don't know it. However, just today I had a very similar problem, for Matlab code. I simply went to the mcode.sty file, and copied the entire list of literate replacements, and then added mine. So the old one looked like this

lstset{%
  literate=%
  {(end)}{lstbasicfont (end)}{5} % black ``end'' when indexing last vector element
  {({ }end)}{lstbasicfont ({ }end)}{6}
  {(end{ })}{lstbasicfont (end{ })}{6}
  {({ }end{ })}{lstbasicfont ({ }end{ })}{7}
  {:end}{lstbasicfont :end}{4}
  {:{ }end}{lstbasicfont :{ }end}{5}
  {end:}{lstbasicfont end:}{4}
  {end{ }:}{lstbasicfont end{ }:}{5}
  {,end}{lstbasicfont ,end}{4}
  {,{ }end}{lstbasicfont ,{ }end}{5}
  {µ}{$mu$}1
  {~}{{fontfamily{ptm}selectfonttexttildelow}}1 % get a nicer tilde character
  }

and I changed that to

lstset{%
  literate=%
    {(end)}{lstbasicfont (end)}{5} % black ``end'' when indexing last vector element
    {({ }end)}{lstbasicfont ({ }end)}{6}
    {(end{ })}{lstbasicfont (end{ })}{6}
    {({ }end{ })}{lstbasicfont ({ }end{ })}{7}
    {:end}{lstbasicfont :end}{4}
    {:{ }end}{lstbasicfont :{ }end}{5}
    {end:}{lstbasicfont end:}{4}
    {end{ }:}{lstbasicfont end{ }:}{5}
    {,end}{lstbasicfont ,end}{4}
    {,{ }end}{lstbasicfont ,{ }end}{5}
    {µ}{$mu$}1
    {~}{{fontfamily{ptm}selectfonttexttildelow}}1 % get a nicer tilde character
    {×}{$times$}1 % W.E.D. added on 1/18/2021
  }

So, if you can find which package you are using that already defines a literate list, just copy and paste that into your document along with your addition.

Answered by Ethan Duckworth on July 22, 2021

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