1

I have some code snippets in which I'd like to use the characters ĉ,ĝ,ĥ,ĵ,ŝ,ŭ. However the listings package is unable to process them well, resulting in compilation errors or other oddities. my MWE using lualatex:

\documentclass[12pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{listings}
\usepackage{fontspec}

\begin{document}

\begin{lstlisting}
tagmango
\end{lstlisting}

\begin{lstlisting}
tagman\^go
\end{lstlisting}

\begin{lstlisting}
tagmanĝo
\end{lstlisting}

\end{document}

this is the result with fontspec commented out:

with fontspec commented out

this is the result time using fontspec:

this time using fontspec

this post and this one seemed to have a solution using some specific listings command, but I just don't understand the inner workings of this solution (is the argument a list encoding every desired unicode character? is it just a long voodo string that does something?) and how to minimally adapt it to my use case. couldn't find any mention of it in the listings' package manual either.

Nailo
  • 37
  • 1
    (1) welcome, (2) inputenc is irrelevant with lualatex, (3) utf8x is not really being used any more (in pdflatex based docs). (4) listing is from a time before 2byte chars was the norm, thus its internal workings rely on things being 1byte or being able to transform to tex codes. That is how we usually handle utf8 in listings through the literal option for listings. This also explains why this stuff is not mentioned in the listings manual it is simply from a different time. – daleif Jul 21 '18 at 11:39
  • For the solution in the first link, you'll need to know the hex number for each utf8 char you need and then add them to the list with ^^^^ i front. Here g-har is ^^^^011d (i just googled g hat unicode) – daleif Jul 21 '18 at 11:43
  • 2
    You could try minted as an alternative to listings, that would (probably) work well with utf8 characters. – Marijn Jul 21 '18 at 22:05

0 Answers0