简体   繁体   中英

non-ASCII characters in Julia sourcefiles (e.g. θ) come out mojibake (e.g. Îÿ) using '\lstinputlisting{}' in LaTeX

I would like to include some Julia source in a LaTeX doc. I am familiar with the 'listings' package, and have crafted a decent 'lstdefinelanguage'. But I am having trouble with non-ASCII characters in the jl. I have played around with various 'lstset' and 'inputenc' options like 'extendedchars' and 'utf8' to no avail. I am using TeXShop on a Mac. Has anyone cracked this?

You can use literate option although it requires some set-up work. Here is a MWE:

\documentclass{article}
\usepackage{listings}
\usepackage{courier}

\lstset{basicstyle=\ttfamily}
\lstset{literate=
    {δ}{{$\delta$}}1
    {ϵ}{{$\epsilon$}}1
}

\begin{document}
\begin{lstlisting}
function f()
    ϵϵϵϵϵ = 1
    xxxxx = 3
    δδδδδ = 2
    ϵ + x + δ
end
\end{lstlisting}
\end{document}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM