LaTeX writer/template: Improve babel support.

Previously we used the `.ini` files for every language, but
for European languages these tend to provide inferior results
to the `.ldf` files used by classic Babel. Currently Babel
documentation recommends using the classic system for European
languages written in Latin and Cyrillic scripts and Vietnamese.
So the LaTeX writer and template now follow this guidance.

Main languages in the list of languages with good "classic" support
are added to global documentclass options and will be automatically
handled by Babel using the `.ldf` files.

If the main language is not in this list, the `babeloptions` variable
will be set to `provide=*`, which will cause support to be loaded from
the `.ini` file rather than an `.ldf`. So, for example, setting
`-V babeloptions=''` with a polytonic Greek document will cause the
`.ldf` support to be used instead of the `.ini`.

The default setting of this variable can be overwritten, but in most
cases the default should give good results.

Closes #8283.
This commit is contained in:
John MacFarlane
2025-02-04 22:21:06 -08:00
parent 1a3ea44f4f
commit 9be0963327
6 changed files with 123 additions and 15 deletions
+7
View File
@@ -3043,6 +3043,13 @@ Pandoc uses these variables when [creating a PDF] with a LaTeX engine.
`csquotesoptions`
: options to use for `csquotes` package (repeat for multiple options).
`babeloptions`
: options to pass to the babel package (may be repeated for
multiple options). This defaults to `provide=*` if the main
language isn't a European language written with Latin or
Cyrillic script or Vietnamese. Most users will not need to
adjust the default setting.
#### Fonts
`fontenc`
+2 -6
View File
@@ -183,12 +183,11 @@ $-- Babel language support
$--
$if(lang)$
\ifLuaTeX
\usepackage[bidi=basic]{babel}
\usepackage[bidi=basic$for(babeloptions)$,$babeloptions$$endfor$]{babel}
\else
\usepackage[bidi=default]{babel}
\usepackage[bidi=default$for(babeloptions)$,$babeloptions$$endfor$]{babel}
\fi
$if(babel-lang)$
\babelprovide[main,import]{$babel-lang$}
$if(mainfont)$
\ifPDFTeX
\else
@@ -196,9 +195,6 @@ $if(mainfont)$
\fi
$endif$
$endif$
$for(babel-otherlangs)$
\babelprovide[import]{$babel-otherlangs$}
$endfor$
$for(babelfonts/pairs)$
\babelfont[$babelfonts.key$]{rm}{$babelfonts.value$}
$endfor$
+6
View File
@@ -1,5 +1,11 @@
$passoptions.latex()$
\documentclass[
$for(babel-otherlangs)$
$babel-otherlangs$,
$endfor$
$if(babel-lang)$
$babel-lang$,
$endif$
$if(fontsize)$
$fontsize$,
$endif$
+100 -1
View File
@@ -265,9 +265,15 @@ pandocToLaTeX options (Pandoc meta blocks) = do
(literal $ renderLang l)) mblang
$ maybe id (\l -> defField "babel-lang"
(literal l)) babelLang
$ (case babelLang of -- see #8283
Just l | l `notElem` ldfLanguages
-> defField "babeloptions" ("provide=*" :: Text)
_ -> id)
$ defField "babel-otherlangs"
(map literal
(nubOrd . catMaybes . filter (/= babelLang)
(filter (`elem` ldfLanguages) .
nubOrd . catMaybes .
filter (/= babelLang)
$ map toBabel docLangs))
$ defField "selnolig-langs"
(literal . T.intercalate "," $
@@ -1187,3 +1193,96 @@ inSoulCommand pa = do
result <- pa
modify $ \st -> st{ stInSoulCommand = oldInSoulCommand }
pure result
-- Babel languages with a .ldf that works well with all engines (see #8283).
-- We follow the guidance from the Babel documentation:
-- "In general, you should do this for European languages written in Latin
-- and Cyrillic scripts, as well as for Vietnamese."
ldfLanguages :: [Text]
ldfLanguages =
[ "magyar"
, "croatian"
, "ngerman"
, "germanb"
, "german"
, "austrian"
, "ngermanb"
, "naustrian"
, "nswissgerman"
, "swissgerman"
, "italian"
, "greek"
, "azerbaijani"
, "american"
, "newzealand"
, "UKenglish"
, "USenglish"
, "australian"
, "british"
, "canadian"
, "english"
, "bahasa"
, "slovak"
, "finnish"
, "occitan"
, "swedish"
, "brazil"
, "portuguese"
, "portuges"
, "brazilian"
, "spanish"
, "norwegian"
, "norsk"
, "nynorsk"
, "bulgarian"
, "breton"
, "belarusian"
, "piedmontese"
, "esperanto"
, "lithuanian"
, "ukraineb"
, "scottishgaelic"
, "scottish"
, "dutch"
, "afrikaans"
, "czech"
, "serbian"
, "latvian"
, "catalan"
, "basque"
, "albanian"
, "irish"
, "serbianc"
, "interlingua"
, "bosnian"
, "friulan"
, "romanian"
, "icelandic"
, "classiclatin"
, "ecclesiasticlatin"
, "medievallatin"
, "latin"
, "georgian"
, "macedonian"
, "welsh"
, "vietnamese"
, "romansh"
, "danish"
, "lsorbian"
, "usorbian"
, "polish-compat"
, "polish"
, "estonian"
, "french"
, "frenchb"
, "canadien"
, "acadian"
, "francais"
, "turkish"
, "hindi"
, "northernsami"
, "samin"
, "russianb"
, "galician"
, "slovene"
]
+2 -2
View File
@@ -12,6 +12,8 @@ More text in English. ['Zitat auf Deutsch.']{lang=de}
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\documentclass[
french,
ngerman,
]{article}
\usepackage{xcolor}
\usepackage{amsmath,amssymb}
@@ -51,8 +53,6 @@ More text in English. ['Zitat auf Deutsch.']{lang=de}
\else
\usepackage[bidi=default]{babel}
\fi
\babelprovide[main,import]{ngerman}
\babelprovide[import]{french}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
+6 -6
View File
@@ -2,6 +2,12 @@
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\documentclass[
ngerman,
british,
nswissgerman,
spanish,
french,
english,
]{article}
\usepackage{xcolor}
\usepackage{amsmath,amssymb}
@@ -41,12 +47,6 @@
\else
\usepackage[bidi=default]{babel}
\fi
\babelprovide[main,import]{english}
\babelprovide[import]{ngerman}
\babelprovide[import]{british}
\babelprovide[import]{nswissgerman}
\babelprovide[import]{spanish}
\babelprovide[import]{french}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}