aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/LaTeX.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-07-22 14:23:26 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2020-07-22 14:23:26 -0700
commit65865b31867efcdf28c51526797fc1b8ec7685a6 (patch)
treec87f38e9ed78686c0298d4e5ccb56a8d4684ed86 /src/Text/Pandoc/Readers/LaTeX.hs
parent7faa9d90644b4ae151571e80734365bd96e857dc (diff)
downloadpandoc-65865b31867efcdf28c51526797fc1b8ec7685a6.tar.gz
LaTeX reader: support ams proof environment.
Diffstat (limited to 'src/Text/Pandoc/Readers/LaTeX.hs')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 9543f635d..ac9b8b43b 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -35,6 +35,7 @@ import Data.List (intercalate)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, maybeToList)
import qualified Data.Set as Set
+import qualified Data.Sequence as Seq
import Data.Text (Text)
import qualified Data.Text as T
import System.FilePath (addExtension, replaceExtension, takeExtension)
@@ -1845,6 +1846,8 @@ environments = M.fromList
, ("tikzcd", rawVerbEnv "tikzcd")
, ("lilypond", rawVerbEnv "lilypond")
, ("ly", rawVerbEnv "ly")
+ -- amsthm
+ , ("proof", amsProof)
-- etoolbox
, ("ifstrequal", ifstrequal)
, ("newtoggle", braced >>= newToggle)
@@ -1853,6 +1856,30 @@ environments = M.fromList
, ("iftoggle", try $ ifToggle >> block)
]
+amsProof :: PandocMonad m => LP m Blocks
+amsProof = do
+ title <- option (B.text "Proof") opt
+ bs <- env "proof" blocks
+ return $
+ B.divWith ("", ["proof"], []) $
+ addQed $ addTitle (B.emph (title <> ".")) $ bs
+
+addTitle :: Inlines -> Blocks -> Blocks
+addTitle ils bs =
+ case B.toList bs of
+ (Para xs : rest)
+ -> B.fromList (Para (B.toList ils ++ (Space : xs)) : rest)
+ _ -> B.para ils <> bs
+
+addQed :: Blocks -> Blocks
+addQed bs =
+ case Seq.viewr (B.unMany bs) of
+ s Seq.:> Para ils
+ -> B.Many (s Seq.|> Para (ils ++ B.toList qedSign))
+ _ -> bs <> B.para qedSign
+ where
+ qedSign = B.spanWith ("",["qed"],[]) "\x220E"
+
environment :: PandocMonad m => LP m Blocks
environment = try $ do
controlSeq "begin"