diff options
| author | Hikaru Ibayashi <hikaru.ccm1023@gmail.com> | 2023-12-10 09:29:45 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-10 09:29:45 -0800 |
| commit | 3be253fb90deb8ca746156a3b281e5983fc6e8cf (patch) | |
| tree | 7f6474c7ff9c90d7b1e1bc2b5039830913391474 /src | |
| parent | aa9577074357c7938c5a4a7e820bd12c90c0d32b (diff) | |
LaTeX writer: fix bug with big footnotes inside emphasis (#9168)
Closes #8982.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 1b1966e05..8aa085ca5 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -64,11 +64,39 @@ import Text.Pandoc.Writers.LaTeX.Util (stringToLaTeX, StringContext(..), getListingsLanguage, mbBraced) import Text.Pandoc.Writers.Shared import qualified Text.Pandoc.Writers.AnnotatedTable as Ann +-- Work around problems with notes inside emphasis (see #8982) + +isolateBigNotes :: ([Inline] -> Inline) -> [Inline] -> [Inline] +isolateBigNotes constructor xs = + let (before, after) = break isBigNote xs + in case after of + (noteInline:rest) -> constructor before : + noteInline : + isolateBigNotes constructor rest + [] -> [constructor xs] + where + isBigNote :: Inline -> Bool + isBigNote (Note [Plain _]) = False -- A small note + isBigNote (Note [Para _]) = False -- A small note + isBigNote (Note _) = True -- A big note + isBigNote _ = False -- Not a note + +raiseBigNotes :: [Inline] -> [Inline] +raiseBigNotes (Emph inner : xs) + = isolateBigNotes Emph (raiseBigNotes inner) ++ raiseBigNotes xs +raiseBigNotes (Strong inner : xs) + = isolateBigNotes Strong (raiseBigNotes inner) ++ raiseBigNotes xs +raiseBigNotes (Underline inner : xs) + = isolateBigNotes Underline (raiseBigNotes inner) ++ raiseBigNotes xs +raiseBigNotes (Strikeout inner : xs) + = isolateBigNotes Strikeout (raiseBigNotes inner) ++ raiseBigNotes xs +raiseBigNotes (x : xs) = x : raiseBigNotes xs +raiseBigNotes [] = [] -- | Convert Pandoc to LaTeX. writeLaTeX :: PandocMonad m => WriterOptions -> Pandoc -> m Text writeLaTeX options document = - evalStateT (pandocToLaTeX options document) $ + evalStateT (pandocToLaTeX options (walk raiseBigNotes document)) $ startingState options -- | Convert Pandoc to LaTeX Beamer. |
