diff options
| author | John MacFarlane <[email protected]> | 2024-02-18 11:44:03 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-02-18 11:44:03 -0800 |
| commit | b36052144b3fe49077ad70c6bd54d4747a4c0d03 (patch) | |
| tree | 3838a4fb7f7d652f2d4cf0ec9dc6840ad850608a /src | |
| parent | 8d63ed444901d0c5ef675788dbd90ea99e2f494c (diff) | |
LaTeX writer: fix bug when a language is specified in two different ways.
If you used `lang: de-DE` but then had a span or div with `lang=de`, the
preamble would try to load `ngerman` twice, leading to an error.
This fix ensures that a language is only loaded once.
Closes #9472.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 9eb7be4f6..2c3404310 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -175,7 +175,6 @@ pandocToLaTeX options (Pandoc meta blocks) = do titleMeta <- stringToLaTeX TextString $ stringify $ docTitle meta authorsMeta <- mapM (stringToLaTeX TextString . stringify) $ docAuthors meta -- we need a default here since lang is used in template conditionals - let otherLangs = [l | l <- docLangs, mblang /= Just l] let hasStringValue x = isJust (getField x metadata :: Maybe (Doc Text)) let geometryFromMargins = mconcat $ intersperse ("," :: Doc Text) $ mapMaybe (\(x,y) -> @@ -251,15 +250,18 @@ pandocToLaTeX options (Pandoc meta blocks) = do -> resetField "papersize" ("a" <> ds) _ -> id) metadata + let babelLang = mblang >>= toBabel let context' = -- note: lang is used in some conditionals in the template, -- so we need to set it if we have any babel/polyglossia: maybe id (\l -> defField "lang" (literal $ renderLang l)) mblang $ maybe id (\l -> defField "babel-lang" - (literal l)) (mblang >>= toBabel) + (literal l)) babelLang $ defField "babel-otherlangs" - (map literal $ mapMaybe toBabel otherLangs) + (map literal + (nubOrd . catMaybes . filter (/= babelLang) + $ map toBabel docLangs)) $ defField "latex-dir-rtl" ((render Nothing <$> getField "dir" context) == Just ("rtl" :: Text)) context |
