TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm submitting a paper to a journal using LaTeX, and I need to be able to write Unicode symbols into listings. So far, I've been able to get by with the moreverb package. It's listing environment is pretty good in conjunction with the utf8x set on inputenc. However, some symbols, like Σ, just won't work.

Note: I'm using listings because the contents are code-snippets and not traditional math expressions. Here are some minimal examples.

\documentclass[preprint, 11pt]{sigplanconf}

This works:

test = 2 ∈ s

This doesn't work:

sum = Σ(s)

Please help!

share|improve this question
First question in such cases is always: can you switch to XeLaTeX/LuaLaTeX or do you have to use pdfLaTeX? – Philipp Apr 17 '11 at 14:32
up vote 6 down vote accepted

Your problem is not really listing related; you’ll get the error outside of a listing as well. The point is that Latex simply does not understand how to display the unicode characters.

With math characters, this would be easy to solve, however, because of the moreverb environment, you cannot use math directly inside the listing. Luckily, the inputenc package gives you a way out. You need to explicitly tell Latex, how it should render unknown utf8 characters.



%% or simply use the newunicodechar package
%% which does the same without the need of remembering numbers:
% \usepackage{newunicodechar}
% \newunicodechar{Σ}{\ensuremath{\Sigma}}
% \newunicodechar{∈}{\ensuremath{\in}}

∈ Σ

test = 2 ∈ s

sum = Σ(s)


Edit: Changed to use \ensuremath instead of $..$

Edit 2: Added code for the newunicodechar package

Note: You are not restricted to use math mode. You may as well change to another font which includes the needed character somewhere and use it directly.

share|improve this answer
Thank you. This is exactly what I needed! – mepcotterell Apr 18 '11 at 13:08
There is also the newunicodechar package; you get the same as with the first \DeclareUnicodeCharacter by saying \newunicodechar{Σ}{\ensuremath{\Sigma}}. This spares the user from searching the code point of the Σ. Disclaimer: I'm the author of the package. :) – egreg Apr 19 '11 at 12:28
@egreg: Great. I have included the information. – Debilski Apr 19 '11 at 14:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.