git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: handle optional args in raw `\titleformat`.

Closes #3804.

commit7191fe1f29f2f8b45f9be7e0f8bc9ed889e431d2 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 21 Jul 2017, 09:28 (9 years ago) parent992943d
2 files changed+21−8
src/Text/Pandoc/Readers/LaTeX.hs+15−8 test/command/3804.md+6
src/Text/Pandoc/Readers/LaTeX.hs+15−8
@@ -1362,14 +1362,20 @@ rawInlineOr name' fallback = do
13621362
13631363getRawCommand :: PandocMonad m => Text -> LP m String
13641364getRawCommand txt = do
1365− (_, rawargs) <- withRaw
1366− ((if txt == "\\write"
1367− then () <$ satisfyTok isWordTok -- digits
1368− else return ()) *>
1369− skipangles *>
1370− skipopts *>
1371− option "" (try (optional sp *> dimenarg)) *>
1372− many braced)
1365+ (_, rawargs) <- withRaw $
1366+ case txt of
1367+ "\\write" -> do
1368+ void $ satisfyTok isWordTok -- digits
1369+ void braced
1370+ "\\titleformat" -> do
1371+ void braced
1372+ skipopts
1373+ void $ count 4 braced
1374+ _ -> do
1375+ skipangles
1376+ skipopts
1377+ option "" (try (optional sp *> dimenarg))
1378+ void $ many braced
13731379 return $ T.unpack (txt <> untokenize rawargs)
13741380
13751381isBlockCommand :: Text -> Bool
@@ -1397,6 +1403,7 @@ treatAsBlock = Set.fromList
13971403 , "newpage"
13981404 , "clearpage"
13991405 , "pagebreak"
1406+ , "titleformat"
14001407 ]
14011408
14021409isInlineCommand :: Text -> Bool
test/command/3804.mdnew file+6
@@ -0,0 +1,6 @@
1+```
2+% pandoc -t native
3+\titleformat{\chapter}[display]{\normalfont\large\bfseries}{第\thechapter{}章}{20pt}{\Huge}
4+^D
5+[RawBlock (Format "latex") "\\titleformat{\\chapter}[display]{\\normalfont\\large\\bfseries}{\31532\\thechapter{}\31456}{20pt}{\\Huge}"]
6+```