diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-07-22 23:30:41 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-07-22 23:30:41 -0700 |
commit | cdaaaa3f63a18ffdeec87973915d0e68cd1945a8 (patch) | |
tree | 17de37723d4055ee4ca77c12496f4778aa2c5073 | |
parent | f014d71a2f6f8f4dd85bd6b9448a69404aefb501 (diff) | |
download | pandoc-cdaaaa3f63a18ffdeec87973915d0e68cd1945a8.tar.gz |
Implement first optional argument for `\newtheorem`.
This allows groups of theorem environments to be
put in the same numbering sequence.
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 21bd5de88..1538354e3 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1861,9 +1861,12 @@ newtheorem :: PandocMonad m => LP m Blocks newtheorem = do number <- option True (False <$ symbol '*' <* sp) name <- untokenize <$> braced - series <- option Nothing $ Just <$> rawopt + sp + series <- option Nothing $ Just . untokenize <$> bracketedToks + sp showName <- untokenize <$> braced - syncTo <- option Nothing $ Just <$> rawopt + sp + syncTo <- option Nothing $ Just . untokenize <$> bracketedToks let spec = TheoremSpec { theoremName = showName , theoremSeries = series , theoremSyncTo = syncTo @@ -1919,27 +1922,31 @@ lookupTheoremEnvironment name = do mblabel <- option Nothing $ Just . untokenize <$> try (spaces >> controlSeq "label" >> spaces >> braced) bs <- env name blocks - number <- if theoremNumber tspec - then do - num <- getNextNumber - (fromMaybe (DottedNum [0]) . - fmap theoremLastNum . - M.lookup name . sTheoremMap) - updateState $ \s -> - s{ sTheoremMap = - M.insert name - tspec{ theoremLastNum = num } - (sTheoremMap s) - } - case mblabel of - Just ident -> - updateState $ \s -> - s{ sLabels = M.insert ident - [Str (theoremName tspec), Str "\160", - Str (renderDottedNum num)] (sLabels s) } - Nothing -> return () - return $ space <> B.text (renderDottedNum num) - else return mempty + number <- + if theoremNumber tspec + then do + let name' = fromMaybe name $ theoremSeries tspec + num <- getNextNumber + (fromMaybe (DottedNum [0]) . + fmap theoremLastNum . + M.lookup name' . sTheoremMap) + updateState $ \s -> + s{ sTheoremMap = + M.adjust + (\spec -> spec{ theoremLastNum = num }) + name' + (sTheoremMap s) + } + + case mblabel of + Just ident -> + updateState $ \s -> + s{ sLabels = M.insert ident + [Str (theoremName tspec), Str "\160", + Str (renderDottedNum num)] (sLabels s) } + Nothing -> return () + return $ space <> B.text (renderDottedNum num) + else return mempty let title = B.strong (B.text (theoremName tspec) <> number) <> optTitle <> space return $ divWith ("", [name], []) $ addTitle title $ |