aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-02-04 22:21:06 -0800
committerJohn MacFarlane <[email protected]>2025-02-08 10:45:11 -0800
commit9be096332727ad62e9fcd50188980d376003f7fa (patch)
tree355858231834e343c79a03ea1bd78fdc09ac82f2 /src
parent1a3ea44f4fc53deccd1896d9f21a07a19af54cac (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs101
1 files changed, 100 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 77d40c3e7..93601a72e 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -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"
+ ]