LaTeX writer: ignore languages with no babel equivalent...

instead of generating an invalid command in the preamble.
Closes #8325.
This commit is contained in:
John MacFarlane
2022-09-26 21:37:38 -07:00
parent de0e3ff5f6
commit efea562234
3 changed files with 115 additions and 117 deletions
+5 -6
View File
@@ -208,9 +208,9 @@ pandocToLaTeX options (Pandoc meta blocks) = do
maybe id (\l -> defField "lang"
(literal $ renderLang l)) mblang
$ maybe id (\l -> defField "babel-lang"
(literal $ toBabel l)) mblang
(literal l)) (mblang >>= toBabel)
$ defField "babel-otherlangs"
(map (literal . toBabel) docLangs)
(map literal $ mapMaybe toBabel docLangs)
$ defField "latex-dir-rtl"
((render Nothing <$> getField "dir" context) ==
Just ("rtl" :: Text)) context
@@ -738,10 +738,9 @@ inlineToLaTeX (Span (id',classes,kvs) ils) = do
kvToCmd ("dir","ltr") = Just "LR"
kvToCmd _ = Nothing
langCmds =
case lang of
Just lng -> let l = toBabel lng
in ["foreignlanguage{" <> l <> "}"]
Nothing -> []
case lang >>= toBabel of
Just l -> ["foreignlanguage{" <> l <> "}"]
Nothing -> []
let cmds = mapMaybe classToCmd classes ++ mapMaybe kvToCmd kvs ++ langCmds
contents <- inlineListToLaTeX ils
return $
+108 -108
View File
@@ -21,125 +21,125 @@ import Text.Collate.Lang (Lang(..))
-- http://mirrors.ctan.org/macros/latex/required/babel/base/babel.pdf
-- List of supported languages (slightly outdated):
-- http://tug.ctan.org/language/hyph-utf8/doc/generic/hyph-utf8/hyphenation.pdf
toBabel :: Lang -> Text
toBabel :: Lang -> Maybe Text
toBabel (Lang "de" _ (Just "AT") vars _ _)
| "1901" `elem` vars = "austrian"
| otherwise = "naustrian"
| "1901" `elem` vars = Just "austrian"
| otherwise = Just "naustrian"
toBabel (Lang "de" _ (Just "CH") vars _ _)
| "1901" `elem` vars = "swissgerman"
| otherwise = "nswissgerman"
| "1901" `elem` vars = Just "swissgerman"
| otherwise = Just "nswissgerman"
toBabel (Lang "de" _ _ vars _ _)
| "1901" `elem` vars = "german"
| otherwise = "ngerman"
toBabel (Lang "dsb" _ _ _ _ _) = "lowersorbian"
| "1901" `elem` vars = Just "german"
| otherwise = Just "ngerman"
toBabel (Lang "dsb" _ _ _ _ _) = Just "lowersorbian"
toBabel (Lang "el" _ _ vars _ _)
| "polyton" `elem` vars = "polutonikogreek"
toBabel (Lang "en" _ (Just "AU") _ _ _) = "australian"
toBabel (Lang "en" _ (Just "CA") _ _ _) = "canadian"
toBabel (Lang "en" _ (Just "GB") _ _ _) = "british"
toBabel (Lang "en" _ (Just "NZ") _ _ _) = "newzealand"
toBabel (Lang "en" _ (Just "UK") _ _ _) = "british"
toBabel (Lang "en" _ (Just "US") _ _ _) = "american"
toBabel (Lang "fr" _ (Just "CA") _ _ _) = "canadien"
| "polyton" `elem` vars = Just "polutonikogreek"
toBabel (Lang "en" _ (Just "AU") _ _ _) = Just "australian"
toBabel (Lang "en" _ (Just "CA") _ _ _) = Just "canadian"
toBabel (Lang "en" _ (Just "GB") _ _ _) = Just "british"
toBabel (Lang "en" _ (Just "NZ") _ _ _) = Just "newzealand"
toBabel (Lang "en" _ (Just "UK") _ _ _) = Just "british"
toBabel (Lang "en" _ (Just "US") _ _ _) = Just "american"
toBabel (Lang "fr" _ (Just "CA") _ _ _) = Just "canadien"
toBabel (Lang "fra" _ _ vars _ _)
| "aca" `elem` vars = "acadian"
toBabel (Lang "grc" _ _ _ _ _) = "ancientgreek"
toBabel (Lang "hsb" _ _ _ _ _) = "uppersorbian"
| "aca" `elem` vars = Just "acadian"
toBabel (Lang "grc" _ _ _ _ _) = Just "ancientgreek"
toBabel (Lang "hsb" _ _ _ _ _) = Just "uppersorbian"
toBabel (Lang "la" _ _ vars _ _)
| "x-classic" `elem` vars = "classiclatin"
toBabel (Lang "pt" _ (Just "BR") _ _ _) = "brazilian"
toBabel (Lang "sl" _ _ _ _ _) = "slovene"
| "x-classic" `elem` vars = Just "classiclatin"
toBabel (Lang "pt" _ (Just "BR") _ _ _) = Just "brazilian"
toBabel (Lang "sl" _ _ _ _ _) = Just "slovene"
toBabel x = commonFromBcp47 x
-- Takes a list of the constituents of a BCP47 language code
-- and converts it to a string shared by Babel and Polyglossia.
-- https://tools.ietf.org/html/bcp47#section-2.1
commonFromBcp47 :: Lang -> Text
commonFromBcp47 (Lang "sr" (Just "Cyrl") _ _ _ _) = "serbianc"
commonFromBcp47 :: Lang -> Maybe Text
commonFromBcp47 (Lang "sr" (Just "Cyrl") _ _ _ _) = Just "serbianc"
commonFromBcp47 (Lang "zh" (Just "Latn") _ vars _ _)
| "pinyin" `elem` vars = "pinyin"
| "pinyin" `elem` vars = Just "pinyin"
commonFromBcp47 (Lang l _ _ _ _ _) = fromIso l
where
fromIso "af" = "afrikaans"
fromIso "am" = "amharic"
fromIso "ar" = "arabic"
fromIso "as" = "assamese"
fromIso "ast" = "asturian"
fromIso "bg" = "bulgarian"
fromIso "bn" = "bengali"
fromIso "bo" = "tibetan"
fromIso "br" = "breton"
fromIso "ca" = "catalan"
fromIso "cy" = "welsh"
fromIso "cs" = "czech"
fromIso "cop" = "coptic"
fromIso "da" = "danish"
fromIso "dv" = "divehi"
fromIso "el" = "greek"
fromIso "en" = "english"
fromIso "eo" = "esperanto"
fromIso "es" = "spanish"
fromIso "et" = "estonian"
fromIso "eu" = "basque"
fromIso "fa" = "farsi"
fromIso "fi" = "finnish"
fromIso "fr" = "french"
fromIso "fur" = "friulan"
fromIso "ga" = "irish"
fromIso "gd" = "scottish"
fromIso "gez" = "ethiopic"
fromIso "gl" = "galician"
fromIso "gu" = "gujarati"
fromIso "he" = "hebrew"
fromIso "hi" = "hindi"
fromIso "hr" = "croatian"
fromIso "hu" = "magyar"
fromIso "hy" = "armenian"
fromIso "ia" = "interlingua"
fromIso "id" = "indonesian"
fromIso "ie" = "interlingua"
fromIso "is" = "icelandic"
fromIso "it" = "italian"
fromIso "ja" = "japanese"
fromIso "km" = "khmer"
fromIso "kmr" = "kurmanji"
fromIso "kn" = "kannada"
fromIso "ko" = "korean"
fromIso "la" = "latin"
fromIso "lo" = "lao"
fromIso "lt" = "lithuanian"
fromIso "lv" = "latvian"
fromIso "ml" = "malayalam"
fromIso "mn" = "mongolian"
fromIso "mr" = "marathi"
fromIso "nb" = "norsk"
fromIso "nl" = "dutch"
fromIso "nn" = "nynorsk"
fromIso "no" = "norsk"
fromIso "nqo" = "nko"
fromIso "oc" = "occitan"
fromIso "or" = "oriya"
fromIso "pa" = "punjabi"
fromIso "pl" = "polish"
fromIso "pms" = "piedmontese"
fromIso "pt" = "portuguese"
fromIso "rm" = "romansh"
fromIso "ro" = "romanian"
fromIso "ru" = "russian"
fromIso "sa" = "sanskrit"
fromIso "se" = "samin"
fromIso "sk" = "slovak"
fromIso "sq" = "albanian"
fromIso "sr" = "serbian"
fromIso "sv" = "swedish"
fromIso "syr" = "syriac"
fromIso "ta" = "tamil"
fromIso "te" = "telugu"
fromIso "th" = "thai"
fromIso "ti" = "ethiopic"
fromIso "tk" = "turkmen"
fromIso "tr" = "turkish"
fromIso "uk" = "ukrainian"
fromIso "ur" = "urdu"
fromIso "vi" = "vietnamese"
fromIso _ = ""
fromIso "af" = Just "afrikaans"
fromIso "am" = Just "amharic"
fromIso "ar" = Just "arabic"
fromIso "as" = Just "assamese"
fromIso "ast" = Just "asturian"
fromIso "bg" = Just "bulgarian"
fromIso "bn" = Just "bengali"
fromIso "bo" = Just "tibetan"
fromIso "br" = Just "breton"
fromIso "ca" = Just "catalan"
fromIso "cy" = Just "welsh"
fromIso "cs" = Just "czech"
fromIso "cop" = Just "coptic"
fromIso "da" = Just "danish"
fromIso "dv" = Just "divehi"
fromIso "el" = Just "greek"
fromIso "en" = Just "english"
fromIso "eo" = Just "esperanto"
fromIso "es" = Just "spanish"
fromIso "et" = Just "estonian"
fromIso "eu" = Just "basque"
fromIso "fa" = Just "farsi"
fromIso "fi" = Just "finnish"
fromIso "fr" = Just "french"
fromIso "fur" = Just "friulan"
fromIso "ga" = Just "irish"
fromIso "gd" = Just "scottish"
fromIso "gez" = Just "ethiopic"
fromIso "gl" = Just "galician"
fromIso "gu" = Just "gujarati"
fromIso "he" = Just "hebrew"
fromIso "hi" = Just "hindi"
fromIso "hr" = Just "croatian"
fromIso "hu" = Just "magyar"
fromIso "hy" = Just "armenian"
fromIso "ia" = Just "interlingua"
fromIso "id" = Just "indonesian"
fromIso "ie" = Just "interlingua"
fromIso "is" = Just "icelandic"
fromIso "it" = Just "italian"
fromIso "ja" = Just "japanese"
fromIso "km" = Just "khmer"
fromIso "kmr" = Just "kurmanji"
fromIso "kn" = Just "kannada"
fromIso "ko" = Just "korean"
fromIso "la" = Just "latin"
fromIso "lo" = Just "lao"
fromIso "lt" = Just "lithuanian"
fromIso "lv" = Just "latvian"
fromIso "ml" = Just "malayalam"
fromIso "mn" = Just "mongolian"
fromIso "mr" = Just "marathi"
fromIso "nb" = Just "norsk"
fromIso "nl" = Just "dutch"
fromIso "nn" = Just "nynorsk"
fromIso "no" = Just "norsk"
fromIso "nqo" = Just "nko"
fromIso "oc" = Just "occitan"
fromIso "or" = Just "oriya"
fromIso "pa" = Just "punjabi"
fromIso "pl" = Just "polish"
fromIso "pms" = Just "piedmontese"
fromIso "pt" = Just "portuguese"
fromIso "rm" = Just "romansh"
fromIso "ro" = Just "romanian"
fromIso "ru" = Just "russian"
fromIso "sa" = Just "sanskrit"
fromIso "se" = Just "samin"
fromIso "sk" = Just "slovak"
fromIso "sq" = Just "albanian"
fromIso "sr" = Just "serbian"
fromIso "sv" = Just "swedish"
fromIso "syr" = Just "syriac"
fromIso "ta" = Just "tamil"
fromIso "te" = Just "telugu"
fromIso "th" = Just "thai"
fromIso "ti" = Just "ethiopic"
fromIso "tk" = Just "turkmen"
fromIso "tr" = Just "turkish"
fromIso "uk" = Just "ukrainian"
fromIso "ur" = Just "urdu"
fromIso "vi" = Just "vietnamese"
fromIso _ = Nothing
+2 -3
View File
@@ -237,9 +237,8 @@ wrapDiv (_,classes,kvs) t = do
Just "rtl" -> align "RTL"
Just "ltr" -> align "LTR"
_ -> id
wrapLang txt = case lang of
Just lng -> let l = toBabel lng
in inCmd "begin" "otherlanguage"
wrapLang txt = case lang >>= toBabel of
Just l -> inCmd "begin" "otherlanguage"
<> (braces (literal l))
$$ blankline <> txt <> blankline
$$ inCmd "end" "otherlanguage"