Why can't my build produce certain Greek symbols?
The best solution is using a font that supports Greek. However, something can be done also in the case you don't have this support.
If the parts in Greek are very small and questions about hyphenation don't bother you, then no markup is necessary, which would be if longer parts are necessary; in this case using the features provided by polyglossia
and defining \greekfont
is sufficient, together with defining a font for Greek.
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{greek}
\newfontfamily\greekfont{GFS Artemisia}[
Scale=MatchUppercase
]
\title{Beta Test}
\begin{document}
\maketitle
Here is a \textgreek{β} beta.
\end{document}
If you just occasionally use Greek letters, a solution with ucharclasses
is simpler:
\documentclass{article}
\usepackage{fontspec}
\usepackage[Latin,Greek]{ucharclasses}
\newfontfamily\greekfont{GFS Artemisia}[
Scale=MatchUppercase
]
\setTransitionsForGreek{\begingroup\greekfont}{\endgroup}
\title{Beta Test}
\begin{document}
\maketitle
Here is a β beta.
\end{document}
This question just got bumped up, perhaps so other questions can be merged into it. As of 2020, you can accomplish this in LuaLaTeX using babel
, without \textgreek
, \foreignlanguage{greek}
or any other commands in the body of the document at all.
\documentclass{article}
\tracinglostchars=2 % Warn if any character is missing
\usepackage[english]{babel}
\usepackage{unicode-math} % Or fontspec, fontsetup, etc.
\usepackage{microtype} % Enable font expansion and protrusion
\usepackage[paperwidth=10cm]{geometry} % Narrow the MWE
\pagestyle{empty} % Suppress page numbers
\babelprovide[import=el, onchar=ids fonts]{greek} % Or import=el-polyton
\babelfont{rm}
[Language=Default]{NewComputerModernBook}
\babelfont{sf}
[Language=Default]{NewComputerModernSansBook}
\babelfont{tt}
[Language=Default]{NewComputerModernMonoBook}
\setmathfont{NewCMMath-Book}
\begin{document}
Greek (modern Ελληνικά, romanized: El\-lin\-i\-ká, ancient Ἑλληνική,
Hel\-lēn\-i\-kḗ) is an independent branch of the Indo-European family of
languages
Η ελληνική γλώσσα ανήκει στην ινδοευρωπαϊκή οικογένεια και αποτελεί το
μοναδικό μέλος του ελληνικού κλάδου
\end{document}
The default font, Latin Modern Roman, does not support Greek, so it’s necessary to load one that does. The \babelfont
command will set the Script=
and Language=
options for the currently-selected language. it would also let you load a different font as \babelfont[greek]{rm}
, and so on. (Although I turned off language selection for these fonts, to suppress some harmless warning messages.)
Babel also uses the correct hyphenation patterns for the language you are typing in, as you will notice. I needed to add a few hyphenation points to the English transliterations that have accents, manually, with \-
, but native words in both languages are hyphenated properly.
This approach would have problems alternating between full paragraphs in a left-to-right and a right-to-left language, or if you need to change between two different languages that use the same script, but for two left-to-right languages with different alphabets, it works great.
You mentioned that you are using XeTeX. That engine does not support onchar=
, and is also in maintenance mode. I would recommend switching to LuaTeX if you can. If you do need to use XeTeX, one possible solution is to go back to language-tagging commands such as \begin{greek}
. Another would be to use ucharclasses
to change languages whenever you type in Greek, as in egreg’s second MWE, but that package has not worked reliably for me.
I took the text from Wikipedia, so if you have any objection to it, please go and edit those pages.
As the Latin Modern font does not contain Greek symbols, you will have to add them manually from another font. In my example I am taking symbols from the Linux Libertine font.
textgreek
does not work, as the package fontspec
redefines some things here (e.g. \textbeta
).
% arara: xelatex
\documentclass{article}
\usepackage{textgreek}
\usepackage{fontspec}
\usepackage{newunicodechar}
\newfontfamily{\greekfont}{Linux Libertine O}
\newunicodechar{β}{{\greekfont β}}
\begin{document}
β
Δ
\textDelta
\end{document}
I have left out the command \textgreek
. You could redefine it in order to use it with the new symbol, but as I am not sure, what fontspec
is doing with this command, I would rather not touch that.