Math & Scienceusing \mathbb{R} in listings code

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
mikey
Posts: 7
Joined: Tue Feb 16, 2010 9:02 pm

using \mathbb{R} in listings code

Post by mikey »

Hi there,

For some reason when I'm using

Code: Select all

\lstdefinelanguage{mathpseudo}{
	literate={R} {$\mathbb{R}$}{1},
	escapeinside={(*}{*)}
}
And I try a R in my code it just appears as a normal R. If I change \mathbb{R} to say \le then I get a less than or equal sign, and if I put the escape sequence in my code (*$\mathbb{R}$*) I get a properly formatted R...

Does anyone know how to get the function I want?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

using \mathbb{R} in listings code

Post by frabjous »

Try an extra set of braces around $\mathbb{R}$:

Code: Select all

\lstdefinelanguage{mathpseudo}{
   literate={R} {{$\mathbb{R}$}}{1},
   escapeinside={(*}{*)}
}
(See p. 49 of the listings manual.)
mikey
Posts: 7
Joined: Tue Feb 16, 2010 9:02 pm

Re: using \mathbb{R} in listings code

Post by mikey »

Thanks, worked a treat.
Post Reply