8

I'm trying to use the β character in a LaTeX document, but the output PDF never shows it. I am building with xelatex. From the following code:

\documentclass{article}
\usepackage{fontspec,xltxtra,xunicode}
\usepackage{textgreek}

\title{Beta Test}
\begin{document}
\maketitle

% UTF-8 beta and \textbeta don't show in the output.
β    
\textbeta

% However, UTF-8 delta and \textDelta work fine.
Δ
\textDelta

\end{document}

My output will only show the two Δ characters. So UTF-8 and textgreek seem to be fine, except for beta?

2
  • 1
    The Latin Modern font does not support Greek symbols. See tex.stackexchange.com/q/76250 Would you be willing to use an other font? Do you really need this beta as text or could you use $\beta$?
    – LaRiFaRi
    Commented Sep 16, 2014 at 6:22
  • That's a reasonable solution, but actually the β is coming from the title of a reference (in my .bib file). I really want to have my .bib file in UTF-8 as much as possible so that it remains easily portable. For example if I want to import to another ref manager I don't have to rely on that program understanding LaTeX.
    – drgibbon
    Commented Sep 16, 2014 at 17:10

4 Answers 4

4

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}

enter image description here

4
  • Brilliant, thanks! I am using them only occasionally, so the second solution is perfect.
    – drgibbon
    Commented Sep 16, 2014 at 17:12
  • @egreg You're right. I misread the first one. Sorry to bother you.
    – Davislor
    Commented Dec 14, 2020 at 23:57
  • The 2nd solution is the only answer I've been able to find that both works with XeLaTeX and requires no extra commands for placing Greek characters. What are the drawbacks of this solution that make you recommend it only for occasional use?
    – smheidrich
    Commented Jun 1, 2021 at 21:17
  • 1
    @smheidrich If you have long passages in Greek, then you should mark them in order to use correct hyphenation.
    – egreg
    Commented Jun 1, 2021 at 21:26
4

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}

New Computer Modern Book sample

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.

1
  • 1
    Thanks for the update. Back then I was using XeTeX, but I've since switched to LuaTeX.
    – drgibbon
    Commented Dec 15, 2020 at 18:26
2

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}

enter image description here

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.

2

You need very little for Greek typesetting. One of the issues you have is noted above. That of needing a font with the appropriate characters in it. The SBL Cardo font has extensive Greek support, including polytonic and text critical.

You can set up your document so different fonts can be used to typeset various languages. This means you can use your favourite Roman font for English and a specialist font for Greek. See the example below.

The two key elements are \newfontfamily\greekfont{FreeSans}, which tells XeTeX to use the FreeSans font to typeset any Greek. Then in the body, \textgreek{} indicates what characters are Greek. I used a sans font for the Greek to make the distinction clear.

\documentclass{article}
\usepackage{fontspec}

\usepackage{polyglossia}

\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\greekfont{FreeSans}

\setdefaultlanguage[variant=australian]{english}
\setotherlanguage{greek}

\begin{document}
afd AFD

\textgreek{αφδ ΑΦΔ}
\end{document}

enter image description here

1
  • Thanks, ended up using the ucharclasses solution above. After trying a few fonts I'm using Palatino as it seems to be produce nice looking Greek characters.
    – drgibbon
    Commented Sep 16, 2014 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .