@@ -144,11 +144,6 @@ pandocToLaTeX options (Pandoc meta blocks) = do
144 st <- get
144 st <- get
145 titleMeta <- stringToLaTeX TextString $ stringify $ docTitle meta
145 titleMeta <- stringToLaTeX TextString $ stringify $ docTitle meta
146 authorsMeta <- mapM (stringToLaTeX TextString . stringify) $ docAuthors meta
146 authorsMeta <- mapM (stringToLaTeX TextString . stringify) $ docAuthors meta
147− let (mainlang, otherlang) =
148− case (reverse . splitBy (==',') . filter (/=' ')) `fmap`
149− getField "lang" metadata of
150− Just (m:os) -> (m, reverse os)
152 let context = defField "toc" (writerTableOfContents options) $
147 let context = defField "toc" (writerTableOfContents options) $
153 defField "toc-depth" (show (writerTOCDepth options -
148 defField "toc-depth" (show (writerTOCDepth options -
154 if stBook st
149 if stBook st
@@ -173,8 +168,6 @@ pandocToLaTeX options (Pandoc meta blocks) = do
173 defField "euro" (stUsesEuro st) $
168 defField "euro" (stUsesEuro st) $
174 defField "listings" (writerListings options || stLHS st) $
169 defField "listings" (writerListings options || stLHS st) $
175 defField "beamer" (writerBeamer options) $
170 defField "beamer" (writerBeamer options) $
176− defField "mainlang" mainlang $
177− defField "otherlang" otherlang $
178 (if stHighlighting st
171 (if stHighlighting st
179 then defField "highlighting-macros" (styleToLaTeX
172 then defField "highlighting-macros" (styleToLaTeX
180 $ writerHighlightStyle options )
173 $ writerHighlightStyle options )
@@ -186,8 +179,18 @@ pandocToLaTeX options (Pandoc meta blocks) = do
186 defField "biblatex" True
179 defField "biblatex" True
187 _ -> id) $
180 _ -> id) $
182+ let lang = maybe [] (splitBy (=='-')) $ getField "lang" context
183+ (polyLang, polyVar) = toPolyglossia lang
185+ defField "babel-lang" (toBabel lang)
186+ $ defField "polyglossia-lang" polyLang
187+ $ defField "polyglossia-variant" polyVar
188+ $ defField "polyglossia-otherlangs"
189+ (maybe [] (map $ fst . toPolyglossia . splitBy (=='-')) $
190+ getField "otherlangs" context)
189 return $ if writerStandalone options
192 return $ if writerStandalone options
190− then renderTemplate' template context
193+ then renderTemplate' template context'
191 else main
194 else main
193-- | Convert Elements to LaTeX
196-- | Convert Elements to LaTeX
@@ -980,3 +983,132 @@ citationsToBiblatex _ = return empty
980getListingsLanguage :: [String] -> Maybe String
983getListingsLanguage :: [String] -> Maybe String
981getListingsLanguage [] = Nothing
984getListingsLanguage [] = Nothing
982getListingsLanguage (x:xs) = toListingsLanguage x <|> getListingsLanguage xs
985getListingsLanguage (x:xs) = toListingsLanguage x <|> getListingsLanguage xs
987+-- Takes a list of the constituents of a BCP 47 language code and
988+-- converts it to a Polyglossia (language, variant) tuple
989+-- http://mirrors.concertpass.com/tex-archive/macros/latex/contrib/polyglossia/polyglossia.pdf
990+toPolyglossia :: [String] -> (String, String)
991+toPolyglossia ("de":"AT":_) = ("german", "austrian")
992+toPolyglossia ("de":"CH":_) = ("german", "swiss")
993+toPolyglossia ("de":_) = ("german", "")
994+toPolyglossia ("dsb":_) = ("lsorbian", "")
995+toPolyglossia ("el":"poly":_) = ("greek", "poly")
996+toPolyglossia ("en":"AU":_) = ("english", "australian")
997+toPolyglossia ("en":"CA":_) = ("english", "canadian")
998+toPolyglossia ("en":"GB":_) = ("english", "british")
999+toPolyglossia ("en":"NZ":_) = ("english", "newzealand")
1000+toPolyglossia ("en":"UK":_) = ("english", "british")
1001+toPolyglossia ("en":"US":_) = ("english", "american")
1002+toPolyglossia ("grc":_) = ("greek", "ancient")
1003+toPolyglossia ("hsb":_) = ("usorbian", "")
1004+toPolyglossia ("sl":_) = ("slovenian", "")
1005+toPolyglossia x = (commonFromBcp47 x, "")
1007+-- Takes a list of the constituents of a BCP 47 language code and
1008+-- converts it to a Babel language string.
1009+-- http://mirrors.concertpass.com/tex-archive/macros/latex/required/babel/base/babel.pdf
1010+-- Note that the PDF unfortunately does not contain a complete list of supported languages.
1011+toBabel :: [String] -> String
1012+toBabel ("de":"1901":_) = "german"
1013+toBabel ("de":"AT":"1901":_) = "austrian"
1014+toBabel ("de":"AT":_) = "naustrian"
1015+toBabel ("de":_) = "ngerman"
1016+toBabel ("dsb":_) = "lowersorbian"
1017+toBabel ("el":"poly":_) = "polutonikogreek"
1018+toBabel ("en":"AU":_) = "australian"
1019+toBabel ("en":"CA":_) = "canadian"
1020+toBabel ("en":"GB":_) = "british"
1021+toBabel ("en":"NZ":_) = "newzealand"
1022+toBabel ("en":"UK":_) = "british"
1023+toBabel ("en":"US":_) = "american"
1024+toBabel ("fr":"CA":_) = "canadien"
1025+toBabel ("fra":"aca":_) = "acadian"
1026+toBabel ("grc":_) = "polutonikogreek"
1027+toBabel ("hsb":_) = "uppersorbian"
1028+toBabel ("sl":_) = "slovene"
1029+toBabel x = commonFromBcp47 x
1031+-- Takes a list of the constituents of a BCP 47 language code
1032+-- and converts it to a string shared by Babel and Polyglossia.
1033+-- https://tools.ietf.org/html/bcp47#section-2.1
1034+commonFromBcp47 :: [String] -> String
1035+commonFromBcp47 [] = ""
1036+commonFromBcp47 ("pt":"BR":_) = "brazilian"
1037+commonFromBcp47 x = fromIso $ head x
1039+ fromIso "af" = "afrikaans"
1040+ fromIso "am" = "amharic"
1041+ fromIso "ar" = "arabic"
1042+ fromIso "ast" = "asturian"
1043+ fromIso "bg" = "bulgarian"
1044+ fromIso "bn" = "bengali"
1045+ fromIso "bo" = "tibetan"
1046+ fromIso "br" = "breton"
1047+ fromIso "ca" = "catalan"
1048+ fromIso "cy" = "welsh"
1049+ fromIso "cz" = "czech"
1050+ fromIso "cop" = "coptic"
1051+ fromIso "da" = "danish"
1052+ fromIso "dv" = "divehi"
1053+ fromIso "el" = "greek"
1054+ fromIso "en" = "english"
1055+ fromIso "eo" = "esperanto"
1056+ fromIso "es" = "spanish"
1057+ fromIso "et" = "estonian"
1058+ fromIso "eu" = "basque"
1059+ fromIso "fa" = "farsi"
1060+ fromIso "fi" = "finnish"
1061+ fromIso "fr" = "french"
1062+ fromIso "fur" = "friulan"
1063+ fromIso "ga" = "irish"
1064+ fromIso "gd" = "scottish"
1065+ fromIso "gl" = "galician"
1066+ fromIso "he" = "hebrew"
1067+ fromIso "hi" = "hindi"
1068+ fromIso "hr" = "croatian"
1069+ fromIso "hy" = "armenian"
1070+ fromIso "hu" = "magyar"
1071+ fromIso "ia" = "interlingua"
1072+ fromIso "id" = "indonesian"
1073+ fromIso "ie" = "interlingua"
1074+ fromIso "is" = "icelandic"
1075+ fromIso "it" = "italian"
1076+ fromIso "jp" = "japanese"
1077+ fromIso "km" = "khmer"
1078+ fromIso "kn" = "kannada"
1079+ fromIso "ko" = "korean"
1080+ fromIso "la" = "latin"
1081+ fromIso "lo" = "lao"
1082+ fromIso "lt" = "lithuanian"
1083+ fromIso "lv" = "latvian"
1084+ fromIso "ml" = "malayalam"
1085+ fromIso "mn" = "mongolian"
1086+ fromIso "mr" = "marathi"
1087+ fromIso "nb" = "norsk"
1088+ fromIso "nl" = "dutch"
1089+ fromIso "nn" = "nynorsk"
1090+ fromIso "no" = "norsk"
1091+ fromIso "nqo" = "nko"
1092+ fromIso "oc" = "occitan"
1093+ fromIso "pl" = "polish"
1094+ fromIso "pms" = "piedmontese"
1095+ fromIso "pt" = "portuguese"
1096+ fromIso "rm" = "romansh"
1097+ fromIso "ro" = "romanian"
1098+ fromIso "ru" = "russian"
1099+ fromIso "sa" = "sanskrit"
1100+ fromIso "se" = "samin"
1101+ fromIso "sk" = "slovak"
1102+ fromIso "sq" = "albanian"
1103+ fromIso "sr" = "serbian"
1104+ fromIso "sv" = "swedish"
1105+ fromIso "syr" = "syriac"
1106+ fromIso "ta" = "tamil"
1107+ fromIso "te" = "telugu"
1108+ fromIso "th" = "thai"
1109+ fromIso "tk" = "turkmen"
1110+ fromIso "tr" = "turkish"
1111+ fromIso "uk" = "ukrainian"
1112+ fromIso "ur" = "urdu"
1113+ fromIso "vi" = "vietnamese"