@@ -492,20 +492,20 @@ isBlockCommand s = s `M.member` (blockCommands :: M.Map String (LP PandocPure Bl
493inlineEnvironments :: PandocMonad m => M.Map String (LP m Inlines)
493inlineEnvironments :: PandocMonad m => M.Map String (LP m Inlines)
494inlineEnvironments = M.fromList
494inlineEnvironments = M.fromList
495− [ ("displaymath", mathEnv id Nothing "displaymath")
495+ [ ("displaymath", mathEnvWith id Nothing "displaymath")
496− , ("math", math <$> verbEnv "math")
496+ , ("math", math <$> mathEnv "math")
497− , ("equation", mathEnv id Nothing "equation")
497+ , ("equation", mathEnvWith id Nothing "equation")
498− , ("equation*", mathEnv id Nothing "equation*")
498+ , ("equation*", mathEnvWith id Nothing "equation*")
499− , ("gather", mathEnv id (Just "gathered") "gather")
499+ , ("gather", mathEnvWith id (Just "gathered") "gather")
500− , ("gather*", mathEnv id (Just "gathered") "gather*")
500+ , ("gather*", mathEnvWith id (Just "gathered") "gather*")
501− , ("multline", mathEnv id (Just "gathered") "multline")
501+ , ("multline", mathEnvWith id (Just "gathered") "multline")
502− , ("multline*", mathEnv id (Just "gathered") "multline*")
502+ , ("multline*", mathEnvWith id (Just "gathered") "multline*")
503− , ("eqnarray", mathEnv id (Just "aligned") "eqnarray")
503+ , ("eqnarray", mathEnvWith id (Just "aligned") "eqnarray")
504− , ("eqnarray*", mathEnv id (Just "aligned") "eqnarray*")
504+ , ("eqnarray*", mathEnvWith id (Just "aligned") "eqnarray*")
505− , ("align", mathEnv id (Just "aligned") "align")
505+ , ("align", mathEnvWith id (Just "aligned") "align")
506− , ("align*", mathEnv id (Just "aligned") "align*")
506+ , ("align*", mathEnvWith id (Just "aligned") "align*")
507− , ("alignat", mathEnv id (Just "aligned") "alignat")
507+ , ("alignat", mathEnvWith id (Just "aligned") "alignat")
508− , ("alignat*", mathEnv id (Just "aligned") "alignat*")
508+ , ("alignat*", mathEnvWith id (Just "aligned") "alignat*")
511inlineCommands :: PandocMonad m => M.Map String (LP m Inlines)
511inlineCommands :: PandocMonad m => M.Map String (LP m Inlines)
@@ -1187,19 +1187,19 @@ environments = M.fromList
1187 , ("obeylines", parseFromString
1187 , ("obeylines", parseFromString
1188 (para . trimInlines . mconcat <$> many inline) =<<
1188 (para . trimInlines . mconcat <$> many inline) =<<
1189 intercalate "\\\\\n" . lines <$> verbEnv "obeylines")
1189 intercalate "\\\\\n" . lines <$> verbEnv "obeylines")
1190− , ("displaymath", mathEnv para Nothing "displaymath")
1190+ , ("displaymath", mathEnvWith para Nothing "displaymath")
1191− , ("equation", mathEnv para Nothing "equation")
1191+ , ("equation", mathEnvWith para Nothing "equation")
1192− , ("equation*", mathEnv para Nothing "equation*")
1192+ , ("equation*", mathEnvWith para Nothing "equation*")
1193− , ("gather", mathEnv para (Just "gathered") "gather")
1193+ , ("gather", mathEnvWith para (Just "gathered") "gather")
1194− , ("gather*", mathEnv para (Just "gathered") "gather*")
1194+ , ("gather*", mathEnvWith para (Just "gathered") "gather*")
1195− , ("multline", mathEnv para (Just "gathered") "multline")
1195+ , ("multline", mathEnvWith para (Just "gathered") "multline")
1196− , ("multline*", mathEnv para (Just "gathered") "multline*")
1196+ , ("multline*", mathEnvWith para (Just "gathered") "multline*")
1197− , ("eqnarray", mathEnv para (Just "aligned") "eqnarray")
1197+ , ("eqnarray", mathEnvWith para (Just "aligned") "eqnarray")
1198− , ("eqnarray*", mathEnv para (Just "aligned") "eqnarray*")
1198+ , ("eqnarray*", mathEnvWith para (Just "aligned") "eqnarray*")
1199− , ("align", mathEnv para (Just "aligned") "align")
1199+ , ("align", mathEnvWith para (Just "aligned") "align")
1200− , ("align*", mathEnv para (Just "aligned") "align*")
1200+ , ("align*", mathEnvWith para (Just "aligned") "align*")
1201− , ("alignat", mathEnv para (Just "aligned") "alignat")
1201+ , ("alignat", mathEnvWith para (Just "aligned") "alignat")
1202− , ("alignat*", mathEnv para (Just "aligned") "alignat*")
1202+ , ("alignat*", mathEnvWith para (Just "aligned") "alignat*")
1205figure :: PandocMonad m => LP m Blocks
1205figure :: PandocMonad m => LP m Blocks
@@ -1264,19 +1264,32 @@ listenv name p = try $ do
1264 updateState $ \st -> st{ stateParserContext = oldCtx }
1264 updateState $ \st -> st{ stateParserContext = oldCtx }
1265 return res
1265 return res
1267+mathEnvWith :: PandocMonad m
1267−mathEnv :: PandocMonad m => (Inlines -> a) -> Maybe String -> String -> LP m a
1268+ => (Inlines -> a) -> Maybe String -> String -> LP m a
1268−mathEnv f innerEnv name = f <$> mathDisplay (inner <$> verbEnv name)
1269+mathEnvWith f innerEnv name = f <$> mathDisplay (inner <$> mathEnv name)
1269 where inner x = case innerEnv of
1270 where inner x = case innerEnv of
1270 Nothing -> x
1271 Nothing -> x
1271 Just y -> "\\begin{" ++ y ++ "}\n" ++ x ++
1272 Just y -> "\\begin{" ++ y ++ "}\n" ++ x ++
1272 "\\end{" ++ y ++ "}"
1273 "\\end{" ++ y ++ "}"
1275+mathEnv :: PandocMonad m => String -> LP m String
1279+ let endEnv = try $ controlSeq "end" *> braced >>= guard . (== name)
1280+ charMuncher = skipMany comment *>
1281+ (many1 (noneOf "\\%") <|> try (string "\\%")
1282+ <|> try (string "\\\\") <|> count 1 anyChar)
1283+ res <- concat <$> manyTill charMuncher endEnv
1284+ return $ stripTrailingNewlines res
1274verbEnv :: PandocMonad m => String -> LP m String
1286verbEnv :: PandocMonad m => String -> LP m String
1275verbEnv name = do
1287verbEnv name = do
1276 skipopts
1288 skipopts
1277 optional blankline
1289 optional blankline
1278 let endEnv = try $ controlSeq "end" *> braced >>= guard . (== name)
1290 let endEnv = try $ controlSeq "end" *> braced >>= guard . (== name)
1291+ charMuncher = anyChar
1279− res <- manyTill anyChar endEnv
1292+ res <- manyTill charMuncher endEnv
1280 return $ stripTrailingNewlines res
1293 return $ stripTrailingNewlines res
1282fancyverbEnv :: PandocMonad m => String -> LP m Blocks
1295fancyverbEnv :: PandocMonad m => String -> LP m Blocks