From 5a244bb7b330de981cd1a59330b8e34e159a64e8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 15 Apr 2012 17:40:58 -0700 Subject: 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. --- src/Text/Pandoc/Readers/LaTeX.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/Text/Pandoc/Readers/LaTeX.hs') 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) -- cgit v1.2.3