summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-12-10 09:54:26 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2023-12-10 09:54:26 -0800
commit2a09252014ca96174b9f1f6982f24365036b76be (patch)
tree30be997f92e1f3e1d7d5d874a308f86ef1eed218
parent61314a02dffa96a31361f33dda96b95ed603c131 (diff)
LaTeX writer: Add performance optimization to #9168.
We only walk the tree to raise big notes if the document contains big notes (it is fast to check). The removes the slight performance penalty of #9168 for most documents.
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 8aa085ca5..6173e2a23 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -64,8 +64,8 @@ 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)
+-- Work around problems with notes inside emphasis (see #8982)
isolateBigNotes :: ([Inline] -> Inline) -> [Inline] -> [Inline]
isolateBigNotes constructor xs =
let (before, after) = break isBigNote xs
@@ -74,12 +74,12 @@ isolateBigNotes constructor xs =
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
+
+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)
@@ -95,9 +95,13 @@ raiseBigNotes [] = []
-- | Convert Pandoc to LaTeX.
writeLaTeX :: PandocMonad m => WriterOptions -> Pandoc -> m Text
-writeLaTeX options document =
- evalStateT (pandocToLaTeX options (walk raiseBigNotes document)) $
- startingState options
+writeLaTeX options document = do
+ let Any hasBigNotes =
+ query (\il -> if isBigNote il then Any True else Any False) document
+ let document' = if hasBigNotes
+ then walk raiseBigNotes document
+ else document
+ evalStateT (pandocToLaTeX options document') $ startingState options
-- | Convert Pandoc to LaTeX Beamer.
writeBeamer :: PandocMonad m => WriterOptions -> Pandoc -> m Text