@@ -77,6 +77,7 @@ module Text.Pandoc.Readers.LaTeX.Parsing
7777 , skipopts
7878 , rawopt
7979 , overlaySpecification
80+ , getNextNumber
8081 ) where
8182
8283import Control.Applicative (many, (<|>))
@@ -848,3 +849,28 @@ isFontSizeCommand "huge" = True
848849isFontSizeCommand "Huge" = True
849850isFontSizeCommand _ = False
850851
852+getNextNumber :: Monad m
853+ => (LaTeXState -> DottedNum) -> LP m DottedNum
854+getNextNumber getCurrentNum = do
855+ st <- getState
856+ let chapnum =
857+ case sLastHeaderNum st of
858+ DottedNum (n:_) | sHasChapters st -> Just n
859+ _ -> Nothing
860+ return . DottedNum $
861+ case getCurrentNum st of
862+ DottedNum [m,n] ->
863+ case chapnum of
864+ Just m' | m' == m -> [m, n+1]
865+ | otherwise -> [m', 1]
866+ Nothing -> [1]
867+ -- shouldn't happen
868+ DottedNum [n] ->
869+ case chapnum of
870+ Just m -> [m, 1]
871+ Nothing -> [n + 1]
872+ _ ->
873+ case chapnum of
874+ Just n -> [n, 1]
875+ Nothing -> [1]
876+