From f7229b147314042f946dfded3b441ab0fae260a0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 9 Mar 2013 10:20:12 -0800 Subject: LaTeX reader: citation handling changes. Previously, a LaTeX citation would always be parsed as a Citation element, with the raw LaTeX in the [Inline] part. Now, the LaTeX citation is parsed as a Citation element only if `--biblio` was specified (i.e. only if there is a nonempty set of references in readerReferences). Otherwise it is parsed as raw LaTeX. This will make it possible to simplify some things in the markdown writer. It also makes the LaTeX reader behave more like the Markdown reader. --- src/Text/Pandoc/Readers/LaTeX.hs | 11 ++++++++--- src/Text/Pandoc/Writers/Markdown.hs | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 5a2ab599b..880997a6d 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1021,7 +1021,10 @@ cites mode multi = try $ do citation :: String -> CitationMode -> Bool -> LP Inlines citation name mode multi = do (c,raw) <- withRaw $ cites mode multi - return $ cite c (rawInline "latex" $ "\\" ++ name ++ raw) + refs <- getOption readerReferences + return $ if null refs + then rawInline "latex" $ "\\" ++ name ++ raw + else cite c mempty complexNatbibCitation :: CitationMode -> LP Inlines complexNatbibCitation mode = try $ do @@ -1040,8 +1043,10 @@ complexNatbibCitation mode = try $ do optional $ char ';' return $ addPrefix pref $ addSuffix suff $ cits' (c:cits, raw) <- withRaw $ grouped parseOne - return $ cite (c{ citationMode = mode }:cits) - (rawInline "latex" $ "\\citetext" ++ raw) + refs <- getOption readerReferences + return $ if null refs + then rawInline "latex" $ "\\citetext" ++ raw + else cite (c{ citationMode = mode}:cits) mempty -- tables diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index aa7764356..c19cad22b 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -644,7 +644,8 @@ inlineToMarkdown opts (LineBreak) | otherwise = return $ " " <> cr inlineToMarkdown _ Space = return space inlineToMarkdown opts (Cite (c:cs) lst) - | not (isEnabled Ext_citations opts) = inlineListToMarkdown opts lst + | not (null lst) = inlineListToMarkdown opts lst + -- if lst is null, citeproc wasn't run; print a pandoc markdown citation | citationMode c == AuthorInText = do suffs <- inlineListToMarkdown opts $ citationSuffix c rest <- mapM convertOne cs -- cgit v1.2.3