@@ -143,6 +143,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
143 , sLabels :: M.Map String [Inline]
143 , sLabels :: M.Map String [Inline]
144 , sHasChapters :: Bool
144 , sHasChapters :: Bool
145 , sToggles :: M.Map String Bool
145 , sToggles :: M.Map String Bool
147 deriving Show
148 deriving Show
@@ -164,6 +165,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
164 , sLabels = M.empty
165 , sLabels = M.empty
165 , sHasChapters = False
166 , sHasChapters = False
166 , sToggles = M.empty
167 , sToggles = M.empty
169instance PandocMonad m => HasQuoteContext LaTeXState m where
171instance PandocMonad m => HasQuoteContext LaTeXState m where
@@ -249,8 +251,7 @@ rawLaTeXParser retokenize parser valParser = do
249applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
251applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
250 => String -> ParserT String s m String
252 => String -> ParserT String s m String
251applyMacros s = (guardDisabled Ext_latex_macros >> return s) <|>
253applyMacros s = (guardDisabled Ext_latex_macros >> return s) <|>
252− do let retokenize = doMacros *>
253− (toksToString <$> many (satisfyTok (const True)))
254+ do let retokenize = toksToString <$> many (satisfyTok (const True))
254 pstate <- getState
255 pstate <- getState
255 let lstate = def{ sOptions = extractReaderOptions pstate
256 let lstate = def{ sOptions = extractReaderOptions pstate
256 , sMacros = extractMacros pstate }
257 , sMacros = extractMacros pstate }
@@ -258,6 +259,7 @@ applyMacros s = (guardDisabled Ext_latex_macros >> return s) <|>
258 case res of
259 case res of
259 Left e -> fail (show e)
260 Left e -> fail (show e)
260 Right s' -> return s'
261 Right s' -> return s'
261tokenize :: SourceName -> Text -> [Tok]
263tokenize :: SourceName -> Text -> [Tok]
262tokenize sourcename = totoks (initialPos sourcename)
264tokenize sourcename = totoks (initialPos sourcename)
@@ -371,11 +373,10 @@ toksToString :: [Tok] -> String
371toksToString = T.unpack . untokenize
373toksToString = T.unpack . untokenize
373satisfyTok :: PandocMonad m => (Tok -> Bool) -> LP m Tok
375satisfyTok :: PandocMonad m => (Tok -> Bool) -> LP m Tok
374−satisfyTok f =
376+satisfyTok f = do
376− res <- tokenPrim (T.unpack . untoken) updatePos matcher
377 doMacros -- apply macros on remaining input stream
377 doMacros -- apply macros on remaining input stream
378− return res
378+ updateState $ \st -> st{ sExpanded = False }
379+ tokenPrim (T.unpack . untoken) updatePos matcher
379 where matcher t | f t = Just t
380 where matcher t | f t = Just t
380 | otherwise = Nothing
381 | otherwise = Nothing
381 updatePos :: SourcePos -> Tok -> [Tok] -> SourcePos
382 updatePos :: SourcePos -> Tok -> [Tok] -> SourcePos
@@ -384,12 +385,14 @@ satisfyTok f =
385doMacros :: PandocMonad m => LP m ()
386doMacros :: PandocMonad m => LP m ()
386doMacros = do
387doMacros = do
388+ expanded <- sExpanded <$> getState
387 verbatimMode <- sVerbatimMode <$> getState
389 verbatimMode <- sVerbatimMode <$> getState
388− unless verbatimMode $ do
390+ unless (expanded || verbatimMode) $ do
389− mbNewInp <- getInput >>= doMacros' 1
391+ mbNewInp <- getInput >>= doMacros' 1
390− case mbNewInp of
392+ case mbNewInp of
391− Nothing -> return ()
393+ Nothing -> return ()
392− Just inp -> setInput inp
394+ Just inp -> setInput inp
395+ updateState $ \st -> st{ sExpanded = True }
394doMacros' :: PandocMonad m => Int -> [Tok] -> LP m (Maybe [Tok])
397doMacros' :: PandocMonad m => Int -> [Tok] -> LP m (Maybe [Tok])
395doMacros' n inp = do
398doMacros' n inp = do