@@ -86,14 +86,22 @@ command = do
8686
8787begin :: [Char] -> GenParser Char st [Char]
8888begin name = try $ do
89− string $ "\\begin{" ++ name ++ "}"
89+ string "\\begin"
90+ spaces
91+ char '{'
92+ string name
93+ char '}'
9094 optional commandArgs
9195 spaces
9296 return name
9397
9498end :: [Char] -> GenParser Char st [Char]
9599end name = try $ do
96− string $ "\\end{" ++ name ++ "}"
100+ string "\\end"
101+ spaces
102+ char '{'
103+ string name
104+ char '}'
97105 return name
98106
99107-- | Returns a list of block elements containing the contents of an
@@ -103,7 +111,9 @@ environment name = try $ begin name >> spaces >> manyTill block (end name) >>~ s
103111
104112anyEnvironment :: GenParser Char ParserState Block
105113anyEnvironment = try $ do
106− string "\\begin{"
114+ string "\\begin"
115+ spaces
116+ char '{'
107117 name <- many letter
108118 star <- option "" (string "*") -- some environments have starred variants
109119 char '}'
@@ -215,10 +225,10 @@ codeBlock = codeBlockWith "verbatim" <|> codeBlockWith "Verbatim" <|> codeBlockW
215225
216226codeBlockWith :: String -> GenParser Char st Block
217227codeBlockWith env = try $ do
218− string ("\\begin{" ++ env ++ "}") -- don't use begin function because it
219− -- gobbles whitespace
220− optional blanklines -- we want to gobble blank lines, but not
221− -- leading space
228+ string "\\begin"
229+ spaces -- don't use begin function because it
230+ string $ "{" ++ env ++ "}" -- gobbles whitespace; we want to gobble
231+ optional blanklines -- blank lines, but not leading space
222232 contents <- manyTill anyChar (try (string $ "\\end{" ++ env ++ "}"))
223233 spaces
224234 let classes = if env == "code" then ["haskell"] else []
@@ -262,7 +272,10 @@ listItem = try $ do
262272
263273orderedList :: GenParser Char ParserState Block
264274orderedList = try $ do
265− string "\\begin{enumerate}"
275+ string "\\begin"
276+ spaces
277+ string "{enumerate}"
278+ spaces
266279 (_, style, delim) <- option (1, DefaultStyle, DefaultDelim) $
267280 try $ do failIfStrict
268281 char '['
@@ -383,7 +396,9 @@ rawLaTeXEnvironment = do
383396-- the whole literal environment as raw TeX.
384397rawLaTeXEnvironment' :: GenParser Char st String
385398rawLaTeXEnvironment' = try $ do
386− string "\\begin{"
399+ string "\\begin"
400+ spaces
401+ char '{'
387402 name <- many1 letter
388403 star <- option "" (string "*") -- for starred variants
389404 let name' = name ++ star
@@ -448,7 +463,9 @@ commandsToIgnore = ["special","pdfannot","pdfstringdef", "index","bibliography"]
448463skipChar :: GenParser Char ParserState Block
449464skipChar = do
450465 satisfy (/='\\') <|>
451− (notFollowedBy' (lookAhead $ string "\\begin{document}") >> anyChar)
466+ (notFollowedBy' (try $
467+ string "\\begin" >> spaces >> string "{document}") >>
468+ anyChar)
452469 spaces
453470 return Null
454471