aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/LaTeX.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-04-15 17:40:58 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-04-15 17:41:45 -0700
commit5a244bb7b330de981cd1a59330b8e34e159a64e8 (patch)
tree48a905dc4da4051100df99b300c61670f05cb851 /src/Text/Pandoc/Readers/LaTeX.hs
parent5146ba0d6e045970bc4b2ec0ebff0a55285e3c18 (diff)
downloadpandoc-5a244bb7b330de981cd1a59330b8e34e159a64e8.tar.gz
LaTeX reader: Make \label and \ref sensitive to --parse-raw.
IF --parse-raw is selected, these will be parsed as raw latex inlines, rather than bracketed text.
Diffstat (limited to 'src/Text/Pandoc/Readers/LaTeX.hs')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 2ea2b2da3..c0b224aaf 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -321,16 +321,19 @@ inlineCommand = try $ do
parseRaw <- stateParseRaw `fmap` getState
star <- option "" (string "*")
let name' = name ++ star
+ let rawargs = withRaw (skipopts *> option "" dimenarg
+ *> many braced) >>= applyMacros' . snd
+ let raw = if parseRaw
+ then (rawInline "latex" . (('\\':name') ++)) <$> rawargs
+ else mempty <$> rawargs
case M.lookup name' inlineCommands of
- Just p -> p
+ Just p -> p <|> raw
Nothing -> case M.lookup name inlineCommands of
- Just p -> p
- Nothing ->
- if parseRaw
- then (rawInline "latex" . (('\\':name') ++)) <$> rawargs
- else mempty <$> rawargs
- where rawargs = withRaw (skipopts *> option "" dimenarg
- *> many braced) >>= applyMacros' . snd
+ Just p -> p <|> raw
+ Nothing -> raw
+
+unlessParseRaw :: LP ()
+unlessParseRaw = getState >>= guard . not . stateParseRaw
isBlockCommand :: String -> Bool
isBlockCommand s = maybe False (const True) $ M.lookup s blockCommands
@@ -350,8 +353,8 @@ inlineCommands = M.fromList $
, ("dots", lit "…")
, ("mdots", lit "…")
, ("sim", lit "~")
- , ("label", inBrackets <$> tok)
- , ("ref", inBrackets <$> tok)
+ , ("label", unlessParseRaw >> (inBrackets <$> tok))
+ , ("ref", unlessParseRaw >> (inBrackets <$> tok))
, ("(", mathInline $ manyTill anyChar (try $ string "\\)"))
, ("[", mathDisplay $ manyTill anyChar (try $ string "\\]"))
, ("ensuremath", mathInline $ braced)