#Maths mode in lstlisting

1 messages · Page 1 of 1 (latest)

true star
#

Hello, I'm writing a project report with my Julia code in appendix. Since julia understand latex and uses mathematical symbol, I'd like to be able to enter maths mode in the lstlisting.
<= and => seem to work but not for \in etc...
Does anyone have an idea ?
Font is cascadia code, same as vscode's default so I assumed there was no problem of enconding
Compiler is lualatex
Thank you

bleak sail
true star
#

Correct

#

Thing is in Julia you can add maths symbols e.g. you type \in then press tab and it will convert to the math symbol

#

Which one is easily understood by the language

#

But I cannot write it this way in the latex document since I can't be in maths mode inside lstlisting

tired topaz
#

Since you are using lualatex, maybe your font contains U+2208 () in text mode?

#

(just checked, looks like it doesn't, but maybe your could borrow the symbol from elsewhere...)

bleak sail
#

On the image on the right it's not doing any conversions, including <= and >=. It just looks like that because you have a font with ligatures I think

#

(you can tell because those glyphs are wider than in the image on the left)

#

basically you can "teach" lstlisting how to deal with the unicode characters (by entering math mode and just using it there)

tired topaz
tired topaz
#

Minimal examples with minted

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{unicode-math}
\setmainfont{Fira Sans}
\setmonofont{Fira Code}
\setmathfont{Fira Math}
\usepackage{minted}  % Requires shell escape
\begin{document}
\begin{minted}{julia}
s(t) ≥ π;
\end{minted}
\end{document}

or just a plain verbatim,

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{unicode-math}
\setmainfont{Fira Sans}
\setmonofont{Fira Code}
\setmathfont{Fira Math}
\begin{document}
\begin{verbatim}
s(t) ≥ π;
\end{verbatim}
\end{document}

Examples are compiled with latexmk -pdflua and optionally -shell-escape when using minted.
As you can see, both environments support unicode out of the box with lualatex.

bleak sail
#

Might be a font issue though, since I was just using the default