2

I have a minimal document:

\documentclass{article}
\begin{document}
this is λ lambda
\end{document}

When building with latex, is gives the error

Package inputenc: Unicode character λ (U+03BB)
(inputenc)    not set up for use with LaTeX.

and when building with lualatex, it outputs:

lambda

(the unicode λ character is invisible)

How to make the λ visible?

  • Do you intend to use λ in text mode or in math mode? – Mico Dec 1 '20 at 20:13
  • Do you load the fontspec and/or unicode-math packages? Which text and math fonts do employ? – Mico Dec 1 '20 at 20:18
  • I intend to use unicode in text, math, and lstlisting. In only load what shown. – Hugo Trentesaux Dec 1 '20 at 20:20
  • 3
    you will have a missing glyph warning in the log for luatex telling you that latin modern does not have a lambda. You need to choose a font via fontspec that includes greek. – David Carlisle Dec 1 '20 at 20:24
  • 1
    Add \tracinglostchars=2 so that the warning (it will say something like: Missing character: There is no λ (U+03BB) in font [lmroman10-regular]:+tlig;!) shows up in the terminal and not just in the log file. Unfortunately, this is not the default (though IMO it should be). – ShreevatsaR Dec 1 '20 at 22:25
5

It's not enough to provide utf8-encoded input. You also need to select text and math fonts that possess the glyphs you wish to typeset.

As the following screenshot reveals, Latin Modern Roman (the default system serif text font) doesn't feature a λ glyph, but Latin Modern Math does -- in both a slanted and in an upright shape. Stix Two, in contrast, possesses a λ glyph in both text and math.

enter image description here

\documentclass{article}
\usepackage{unicode-math} % loads 'fontspec' automatically
\begin{document}
\obeylines % just for this example
\setmainfont{Latin Modern Roman}
\setmathfont{Latin Modern Math}
Latin Modern text and math font
this is λ lambda
this is $λ$ $\symup{λ}$ lambda

\bigskip
\setmainfont{Stix Two Text}
\setmathfont{Stix Two Math}
Stix Two text and math font
this is λ lambda
this is $λ$ $\symup{λ}$ lambda
\end{document}
5

You need to load both a font and an encoding that supports Greek. In LuaLaTeX, that’s Unicode, and you can automatically switch to your Greek language and font whenever you start typing in Greek.

\documentclass{article}
\tracinglostchars=2
\usepackage[english]{babel}
\usepackage{unicode-math}

\babelprovide[import=el, onchar=ids fonts]{greek}

\babelfont{rm}[ Language=Default]{NewComputerModernBook}
\babelfont{sf}[ Language=Default]{NewComputerModernSansBook}
\babelfont{tt}[Language=Default]{NewComputerModernMonoBook}
\setmathfont{NewCMMath-Book}

\pagestyle{empty} % Suppress page numbering

\begin{document}
This is λ lambda.

And \(λ\) in math mode.
\end{document}

New Computer Modern Book Sample

You can define different fonts for \babelfont[greek]{rm}, and Babel will switch to them when you start typing in Greek in text mode. It will use the symbols from your Unicode math font in math mode. You can instead load Polyglossia if you prefer it to Babel.

My advice is to use LuaLaTeX and unicode-math when you can, and legacy 8-bit fonts when you have to. Tn PDFTeX, the 8-bit font encoding you want is called LGR, and you also want alphabeta to enable Greek letters in both text and math mode.

\documentclass{article}
\tracinglostchars=2
\usepackage[LGR,T1]{fontenc}
\usepackage[greek, english]{babel}
\usepackage{alphabeta}

\pagestyle{empty} % Suppress page numbering

\begin{document}
This is λ lambda.

And \(λ\) in math mode.
\end{document}

Computer Modern Roman sample

If your main font does not come in LGR, you can declare a font substitution with substitutefont.

You were getting the error you did because PDFTeX only understands Unicode characters that you’ve set up, and the LaTeX kernel only sets up characters that are in one of the font encodings you’ve loaded.

If you check your .log file from your original LuaLaTeX MWE, you’ll see a warning message buried in the middle of it, saying that there was no λ glyph in the current font. Other than that, TeX silently ignores the error. This is terrible design, but apparently we’re stuck with it for the sake of backward compatibility. The command \tracinglostchars=2 will at least display the warning on the console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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