@@ -112,18 +112,13 @@ data DEnv = DEnv { docxOptions :: ReaderOptions
113type DocxContext = ReaderT DEnv (State DState)
113type DocxContext = ReaderT DEnv (State DState)
115−updateDState :: (DState -> DState) -> DocxContext ()
115+withDState :: (DState -> DState) -> DocxContext a -> DocxContext a
120−withDState :: DState -> DocxContext a -> DocxContext a
121−withDState ds dctx = do
116+withDState f dctx = do
122− ds' <- get
117+ ds <- get
123− updateDState (\_ -> ds)
118+ modify f
124− dctx' <- dctx
119+ ctx' <- dctx
126− return dctx'
121+ return ctx'
128evalDocxContext :: DocxContext a -> DEnv -> DState -> a
123evalDocxContext :: DocxContext a -> DEnv -> DState -> a
129evalDocxContext ctx env st = evalState (runReaderT ctx env) st
124evalDocxContext ctx env st = evalState (runReaderT ctx env) st
@@ -307,8 +302,9 @@ parPartToInlines (BookMark _ anchor) =
307 let newAnchor = case anchor `elem` (M.elems anchorMap) of
302 let newAnchor = case anchor `elem` (M.elems anchorMap) of
308 True -> uniqueIdent [Str anchor] (M.elems anchorMap)
303 True -> uniqueIdent [Str anchor] (M.elems anchorMap)
309 False -> anchor
304 False -> anchor
310− updateDState $ \s -> s { docxAnchorMap = M.insert anchor newAnchor anchorMap}
311 return [Span (anchor, ["anchor"], []) []]
305 return [Span (anchor, ["anchor"], []) []]
306+ modify $ \s -> s { docxAnchorMap = M.insert anchor newAnchor anchorMap}
307+ return [Span (newAnchor, ["anchor"], []) []]
312parPartToInlines (Drawing fp bs) = do
308parPartToInlines (Drawing fp bs) = do
313 return $ case True of -- TODO: add self-contained images
309 return $ case True of -- TODO: add self-contained images
314 True -> [Image [] (fp, "")]
310 True -> [Image [] (fp, "")]
@@ -427,8 +423,8 @@ oMathElemToTexString (Matrix bases) = do
427 s <- liftM (intercalate " \\\\\n")(mapM rowString bases)
423 s <- liftM (intercalate " \\\\\n")(mapM rowString bases)
428 return $ printf "\\begin{matrix}\n%s\n\\end{matrix}" s
424 return $ printf "\\begin{matrix}\n%s\n\\end{matrix}" s
429oMathElemToTexString (NAry style sub sup base) | Just c <- nAryChar style = do
425oMathElemToTexString (NAry style sub sup base) | Just c <- nAryChar style = do
430− ds <- gets (\s -> s{docxInTexSubscript = True})
426+ subString <- withDState (\s -> s{docxInTexSubscript = True}) $
431− subString <- withDState ds $ concatMapM oMathElemToTexString sub
427+ concatMapM oMathElemToTexString sub
432 supString <- concatMapM oMathElemToTexString sup
428 supString <- concatMapM oMathElemToTexString sup
433 baseString <- baseToTexString base
429 baseString <- baseToTexString base
434 return $ case M.lookup c uniconvMap of
430 return $ case M.lookup c uniconvMap of
@@ -505,7 +501,7 @@ makeHeaderAnchor (Header n (_, classes, kvs) ils) =
506 hdrIDMap <- gets docxAnchorMap
502 hdrIDMap <- gets docxAnchorMap
507 let newIdent = uniqueIdent ils (M.elems hdrIDMap)
503 let newIdent = uniqueIdent ils (M.elems hdrIDMap)
508− updateDState $ \s -> s {docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
504+ modify $ \s -> s {docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
509 return $ Header n (newIdent, classes, kvs) ils
505 return $ Header n (newIdent, classes, kvs) ils
510makeHeaderAnchor blk = return blk
506makeHeaderAnchor blk = return blk