jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.6k stars 3.38k forks source link

Greek text in LaTeX not rendering with Babel #2727

Closed adunning closed 5 years ago

adunning commented 8 years ago

With Pandoc 1.16.0.2, the LaTeX writer is not quite configuring Greek text properly for use with Babel. This works:

pandoc -o grc.pdf -sS << EOT

---
lang: grc
...

Τῶν καλῶν καὶ τιμίων τὴν εἴδησιν ὑπολαμβάνοντες, μᾶλλον δ’ ἑτέραν ἑτέρας ἢ κατ’ ἀκρίβειαν ἢ τῷ βελτιόνων τε καὶ θαυμασιωτέρων εἶναι, δι’ ἀμφότερα ταῦτα τὴν περὶ τῆς ψυχῆς ἱστορίαν εὐλόγως ἂν ἐν πρώτοις τιθείημεν.

EOT

But this does not:

pandoc -o grc.pdf -sS << EOT
<div lang="grc">
Τῶν καλῶν καὶ τιμίων τὴν εἴδησιν ὑπολαμβάνοντες, μᾶλλον δ’ ἑτέραν ἑτέρας ἢ κατ’ ἀκρίβειαν ἢ τῷ βελτιόνων τε καὶ θαυμασιωτέρων εἶναι, δι’ ἀμφότερα ταῦτα τὴν περὶ τῆς ψυχῆς ἱστορίαν εὐλόγως ἂν ἐν πρώτοις τιθείημεν.
</div>

EOT

Error message:

! LaTeX Error: Command \textgreek already defined.
               Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.31 ...][]{\foreignlanguage{polutonikogreek}{#2}}

I tried adding Greek to the Spanish and Gallican overrides already used, but it seems it's a bit more complex than that.

The documentation for babel-greek indicates that the polutonikogreek setting Pandoc uses for Babel with both grc and el-polyton is only provided for backwards compatibility. This does not provide the correct hyphenation patterns for the two (the Polyglossia settings distinguish them correctly), and the option has the further problem that it can't be combined with greek in the same document. Instead, the documentation recommends configuring them as \languageattribute{greek}{ancient} and \languageattribute{greek}{polutoniko}, or as package options with \usepackage[greek.ancient,english]{babel} and \usepackage[greek.polutoniko,english]{babel}.

mb21 commented 8 years ago

So are you saying we should replace polutonikogreek with something else for Babel? If so, the place would be here.

adunning commented 8 years ago

As far as I can tell, the three Greek variants simply can't be mixed at all in a single document under Babel, unlike Polyglossia; only one can be chosen, in the preamble. The simplest approach seems to be to refer to all three variants as greek, but to add the appropriate \languageattribute line to babel-newcommands for grc or el-polyton.

The following document renders correctly under LuaLaTeX or XeLaTeX:

\documentclass{minimal}

\usepackage{fontspec}
\setmainfont{GFS Baskerville}

\usepackage[greek,main=english]{babel}
\languageattribute{greek}{ancient}
\newcommand{\textgreek}[2][]{\foreignlanguage{greek}{#2}}
\newenvironment{greek}[2][]{\begin{otherlanguage}{greek}}{\end{otherlanguage}}

\begin{document}

\begin{greek}[variant=ancient]

Τῶν καλῶν καὶ τιμίων τὴν εἴδησιν ὑπολαμβάνοντες, μᾶλλον δ' ἑτέραν ἑτέρας
ἢ κατ' ἀκρίβειαν ἢ τῷ βελτιόνων τε καὶ θαυμασιωτέρων εἶναι, δι' ἀμφότερα
ταῦτα τὴν περὶ τῆς ψυχῆς ἱστορίαν εὐλόγως ἂν ἐν πρώτοις τιθείημεν. δοκεῖ
δὲ καὶ πρὸς ἀλήθειαν ἅπασαν ἡ γνῶσις αὐτῆς μεγάλα συμβάλλεσθαι, μάλιστα
δὲ πρὸς τὴν φύσιν· ἔστι γὰρ οἷον ἀρχὴ τῶν ζῴων.

\end{greek}

\textgreek[variant=ancient]{ἐπιζητοῦμεν δὲ θεωρῆσαι καὶ γνῶναι τήν τε
φύσιν αὐτῆς καὶ τὴν οὐσίαν, εἶθ' ὅσα συμβέβηκε περὶ αὐτήν· ὧν τὰ μὲν
ἴδια πάθη τῆς ψυχῆς εἶναι δοκεῖ, τὰ δὲ δι' ἐκείνην καὶ τοῖς ζῴοις
ὑπάρχειν.}

\end{document}

That still leaves the \textgreek error, which I don't quite understand (it seems to be coming from greek-fontenc rather than Babel), but at least it only occurs under pdfLaTeX.

ousia commented 7 years ago

Sorry, @adunning, it’s been a while since I used LaTeX.

What I remember from more than a decade ago is that you need the following code to have UTF-8 input:

\usepackage{ucs}
\usepackage[utf8x]{inputenc}

Or how does standard LaTeX know that the input file is Unicode-encoded?

adunning commented 5 years ago

This has been fixed in the most recent versions of Babel.

rien333 commented 5 years ago

Which version would that be? My package manager shows that I have babel from texlive-core 2019.50917, yet I still have the ! LaTeX Error: Command \textgreek already defined. ... from above.