@@ -291,6 +291,14 @@ conditionalEscapeString s =
291291 then escapeString s
292292 else s
293293
294+-- Expand Math before normalizing inline list
295+preprocessInlineList :: PandocMonad m
296+ => [Inline]
297+ -> m [Inline]
298+preprocessInlineList (Math t str:xs) = (++ xs) <$> texMathToInlines t str
299+preprocessInlineList (x:xs) = (x:) <$> preprocessInlineList xs
300+preprocessInlineList [] = return []
301+
294302normalizeInlineList :: [Inline] -> [Inline]
295303normalizeInlineList (x : Str "" : xs)
296304 = normalizeInlineList (x:xs)
@@ -327,7 +335,9 @@ fixNotes (x:xs) = x : fixNotes xs
327335inlineListToMuse :: PandocMonad m
328336 => [Inline]
329337 -> StateT WriterState m Doc
330−inlineListToMuse lst = hcat <$> mapM inlineToMuse (fixNotes $ normalizeInlineList lst)
338+inlineListToMuse lst = do
339+ lst' <- preprocessInlineList lst
340+ hcat <$> mapM inlineToMuse (fixNotes $ normalizeInlineList lst')
331341
332342-- | Convert Pandoc inline element to Muse.
333343inlineToMuse :: PandocMonad m
@@ -363,8 +373,8 @@ inlineToMuse (Quoted DoubleQuote lst) = do
363373inlineToMuse (Cite _ lst) = inlineListToMuse lst
364374inlineToMuse (Code _ str) = return $
365375 "<code>" <> text (substitute "</code>" "<</code><code>/code>" str) <> "</code>"
366−inlineToMuse (Math t str) =
367− lift (texMathToInlines t str) >>= inlineListToMuse
376+inlineToMuse Math{} =
377+ fail "Math should be expanded before normalization"
368378inlineToMuse (RawInline (Format f) str) =
369379 return $ "<literal style=\"" <> text f <> "\">" <> text str <> "</literal>"
370380inlineToMuse LineBreak = return $ "<br>" <> cr