aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-04-05 10:12:24 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-04-05 10:14:06 -0700
commitd77e8f45c9eba5dc5aca579a009a4cd78fbcbc54 (patch)
tree05c0391f504232f1db7cc58e27d08a709b471045 /src/Text
parent87dda2109d01098dcf41c01559d3e91e2627cd10 (diff)
downloadpandoc-d77e8f45c9eba5dc5aca579a009a4cd78fbcbc54.tar.gz
LaTEX reader: properly resolve section numbers with \ref and chapters.
Closes #4529.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 52782653e..e1497dfb1 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -164,6 +164,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
, sInTableCell :: Bool
, sLastHeaderNum :: HeaderNum
, sLabels :: M.Map String [Inline]
+ , sHasChapters :: Bool
, sToggles :: M.Map String Bool
}
deriving Show
@@ -183,6 +184,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
, sInTableCell = False
, sLastHeaderNum = HeaderNum []
, sLabels = M.empty
+ , sHasChapters = False
, sToggles = M.empty
}
@@ -1984,9 +1986,13 @@ section starred (ident, classes, kvs) lvl = do
try (spaces >> controlSeq "label"
>> spaces >> toksToString <$> braced)
let classes' = if starred then "unnumbered" : classes else classes
+ when (lvl == 0) $
+ updateState $ \st -> st{ sHasChapters = True }
unless starred $ do
hn <- sLastHeaderNum <$> getState
- let num = incrementHeaderNum lvl hn
+ hasChapters <- sHasChapters <$> getState
+ let lvl' = lvl + if hasChapters then 1 else 0
+ let num = incrementHeaderNum lvl' hn
updateState $ \st -> st{ sLastHeaderNum = num }
updateState $ \st -> st{ sLabels = M.insert lab
[Str (renderHeaderNum num)]