@@ -56,6 +56,7 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
56 ArgSpec (..), Tok (..), TokType (..))
56 ArgSpec (..), Tok (..), TokType (..))
57import Text.Pandoc.Readers.LaTeX.Parsing
57import Text.Pandoc.Readers.LaTeX.Parsing
58import Text.Pandoc.Readers.LaTeX.Accent (accentCommands)
58import Text.Pandoc.Readers.LaTeX.Accent (accentCommands)
59+import Text.Pandoc.Readers.LaTeX.Citation (citationCommands, cites)
59import Text.Pandoc.Readers.LaTeX.Table (tableEnvironments)
60import Text.Pandoc.Readers.LaTeX.Table (tableEnvironments)
60import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
61import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
61 babelLangToBCP47)
62 babelLangToBCP47)
@@ -169,7 +170,7 @@ rawLaTeXInline = do
169 let toks = tokenize "source" inp
170 let toks = tokenize "source" inp
170 raw <- snd <$>
171 raw <- snd <$>
171 ( rawLaTeXParser toks True
172 ( rawLaTeXParser toks True
172− (mempty <$ (controlSeq "input" >> skipMany opt >> braced))
173+ (mempty <$ (controlSeq "input" >> skipMany rawopt >> braced))
174 <|> rawLaTeXParser toks True (inlineEnvironment <|> inlineCommand')
175 <|> rawLaTeXParser toks True (inlineEnvironment <|> inlineCommand')
@@ -311,7 +312,7 @@ blockquote :: PandocMonad m => Bool -> Maybe Text -> LP m Blocks
311blockquote cvariant mblang = do
312blockquote cvariant mblang = do
312 citepar <- if cvariant
313 citepar <- if cvariant
313 then (\xs -> para (cite xs mempty))
314 then (\xs -> para (cite xs mempty))
314− <$> cites NormalCitation False
315+ <$> cites inline NormalCitation False
315 else option mempty $ para <$> bracketed inline
316 else option mempty $ para <$> bracketed inline
316 let lang = mblang >>= babelLangToBCP47
317 let lang = mblang >>= babelLangToBCP47
317 let langdiv = case lang of
318 let langdiv = case lang of
@@ -425,116 +426,6 @@ pDollarsMath n = do
425 else mzero
426 else mzero
426 _ -> (tk :) <$> pDollarsMath n
427 _ -> (tk :) <$> pDollarsMath n
430−addPrefix :: [Inline] -> [Citation] -> [Citation]
431−addPrefix p (k:ks) = k {citationPrefix = p ++ citationPrefix k} : ks
434−addSuffix :: [Inline] -> [Citation] -> [Citation]
435−addSuffix s ks@(_:_) =
437− in init ks ++ [k {citationSuffix = citationSuffix k ++ s}]
440−simpleCiteArgs :: PandocMonad m => LP m [Citation]
441−simpleCiteArgs = try $ do
442− first <- optionMaybe $ toList <$> opt
443− second <- optionMaybe $ toList <$> opt
444− keys <- try $ bgroup *> manyTill citationLabel egroup
445− let (pre, suf) = case (first , second ) of
446− (Just s , Nothing) -> (mempty, s )
447− (Just s , Just t ) -> (s , t )
448− _ -> (mempty, mempty)
449− conv k = Citation { citationId = k
450− , citationPrefix = []
451− , citationSuffix = []
452− , citationMode = NormalCitation
454− , citationNoteNum = 0
456− return $ addPrefix pre $ addSuffix suf $ map conv keys
458−citationLabel :: PandocMonad m => LP m Text
462− (many1 (satisfyTok isWordTok <|> symbolIn bibtexKeyChar)
464− <* optional (symbol ',')
466− where bibtexKeyChar = ".:;?!`'()/*@_+=-&[]" :: [Char]
468−cites :: PandocMonad m => CitationMode -> Bool -> LP m [Citation]
469−cites mode multi = try $ do
472− multiprenote <- optionMaybe $ toList <$> paropt
473− multipostnote <- optionMaybe $ toList <$> paropt
474− let (pre, suf) = case (multiprenote, multipostnote) of
475− (Just s , Nothing) -> (mempty, s)
476− (Nothing , Just t) -> (mempty, t)
477− (Just s , Just t ) -> (s, t)
478− _ -> (mempty, mempty)
479− tempCits <- many1 simpleCiteArgs
481− (k:ks) -> case ks of
482− (_:_) -> return $ (addMprenote pre k : init ks) ++
483− [addMpostnote suf (last ks)]
484− _ -> return [addMprenote pre (addMpostnote suf k)]
486− else count 1 simpleCiteArgs
487− let cs = concat cits
488− return $ case mode of
489− AuthorInText -> case cs of
490− (c:rest) -> c {citationMode = mode} : rest
492− _ -> map (\a -> a {citationMode = mode}) cs
493− where mprenote (k:ks) = (k:ks) ++ [Space]
495− mpostnote (k:ks) = [Str ",", Space] ++ (k:ks)
496− mpostnote _ = mempty
497− addMprenote mpn (k:ks) =
498− let mpnfinal = case citationPrefix k of
499− (_:_) -> mprenote mpn
501− in addPrefix mpnfinal (k:ks)
502− addMprenote _ _ = []
503− addMpostnote = addSuffix . mpostnote
505−citation :: PandocMonad m => Text -> CitationMode -> Bool -> LP m Inlines
506−citation name mode multi = do
507− (c,raw) <- withRaw $ cites mode multi
508− return $ cite c (rawInline "latex" $ "\\" <> name <> untokenize raw)
510−handleCitationPart :: Inlines -> [Citation]
511−handleCitationPart ils =
512− let isCite Cite{} = True
514− (pref, rest) = break isCite (toList ils)
516− (Cite cs _:suff) -> addPrefix pref $ addSuffix suff cs
519−complexNatbibCitation :: PandocMonad m => CitationMode -> LP m Inlines
520−complexNatbibCitation mode = try $ do
522− withRaw $ concat <$> do
524− items <- mconcat <$>
525− many1 (notFollowedBy (symbol ';') >> inline)
528− return $ map handleCitationPart items
531− (c:cits) -> return $ cite (c{ citationMode = mode }:cits)
532− (rawInline "latex" $ "\\citetext" <> untokenize raw)
534−inNote :: Inlines -> Inlines
536− note $ para $ ils <> str "."
538inlineCommand' :: PandocMonad m => LP m Inlines
429inlineCommand' :: PandocMonad m => LP m Inlines
539inlineCommand' = try $ do
430inlineCommand' = try $ do
540 Tok _ (CtrlSeq name) cmd <- anyControlSeq
431 Tok _ (CtrlSeq name) cmd <- anyControlSeq
@@ -553,19 +444,6 @@ inlineCommand' = try $ do
553tok :: PandocMonad m => LP m Inlines
444tok :: PandocMonad m => LP m Inlines
554tok = tokWith inline
445tok = tokWith inline
556−opt :: PandocMonad m => LP m Inlines
558− toks <- try (sp *> bracketedToks <* sp)
559− -- now parse the toks as inlines
561− parsed <- runParserT (mconcat <$> many inline) st "bracketed option" toks
563− Right result -> return result
564− Left e -> throwError $ PandocParsecError (untokenize toks) e
566−paropt :: PandocMonad m => LP m Inlines
567−paropt = parenWrapped inline
569inBrackets :: Inlines -> Inlines
447inBrackets :: Inlines -> Inlines
570inBrackets x = str "[" <> x <> str "]"
448inBrackets x = str "[" <> x <> str "]"
@@ -629,6 +507,7 @@ inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
629inlineCommands =
507inlineCommands =
630 M.union inlineLanguageCommands $
508 M.union inlineLanguageCommands $
631 M.union (accentCommands tok) $
509 M.union (accentCommands tok) $
510+ M.union (citationCommands inline) $
632 M.fromList
511 M.fromList
633 [ ("emph", extractSpaces emph <$> tok)
512 [ ("emph", extractSpaces emph <$> tok)
634 , ("textit", extractSpaces emph <$> tok)
513 , ("textit", extractSpaces emph <$> tok)
@@ -703,7 +582,7 @@ inlineCommands =
703 , ("/", pure mempty) -- italic correction
582 , ("/", pure mempty) -- italic correction
704 , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState
583 , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState
705 guard $ not inTableCell
584 guard $ not inTableCell
706− optional opt
585+ optional rawopt
708 , (",", lit "\8198")
587 , (",", lit "\8198")
709 , ("@", pure mempty)
588 , ("@", pure mempty)
@@ -761,61 +640,6 @@ inlineCommands =
761 , ("proofname", doTerm Translations.Proof)
640 , ("proofname", doTerm Translations.Proof)
762 , ("glossaryname", doTerm Translations.Glossary)
641 , ("glossaryname", doTerm Translations.Glossary)
763 , ("lstlistingname", doTerm Translations.Listing)
642 , ("lstlistingname", doTerm Translations.Listing)
764− , ("cite", citation "cite" NormalCitation False)
765− , ("Cite", citation "Cite" NormalCitation False)
766− , ("citep", citation "citep" NormalCitation False)
767− , ("citep*", citation "citep*" NormalCitation False)
768− , ("citeal", citation "citeal" NormalCitation False)
769− , ("citealp", citation "citealp" NormalCitation False)
770− , ("citealp*", citation "citealp*" NormalCitation False)
771− , ("autocite", citation "autocite" NormalCitation False)
772− , ("smartcite", citation "smartcite" NormalCitation False)
773− , ("footcite", inNote <$> citation "footcite" NormalCitation False)
774− , ("parencite", citation "parencite" NormalCitation False)
775− , ("supercite", citation "supercite" NormalCitation False)
776− , ("footcitetext", inNote <$> citation "footcitetext" NormalCitation False)
777− , ("citeyearpar", citation "citeyearpar" SuppressAuthor False)
778− , ("citeyear", citation "citeyear" SuppressAuthor False)
779− , ("autocite*", citation "autocite*" SuppressAuthor False)
780− , ("cite*", citation "cite*" SuppressAuthor False)
781− , ("parencite*", citation "parencite*" SuppressAuthor False)
782− , ("textcite", citation "textcite" AuthorInText False)
783− , ("citet", citation "citet" AuthorInText False)
784− , ("citet*", citation "citet*" AuthorInText False)
785− , ("citealt", citation "citealt" AuthorInText False)
786− , ("citealt*", citation "citealt*" AuthorInText False)
787− , ("textcites", citation "textcites" AuthorInText True)
788− , ("cites", citation "cites" NormalCitation True)
789− , ("autocites", citation "autocites" NormalCitation True)
790− , ("footcites", inNote <$> citation "footcites" NormalCitation True)
791− , ("parencites", citation "parencites" NormalCitation True)
792− , ("supercites", citation "supercites" NormalCitation True)
793− , ("footcitetexts", inNote <$> citation "footcitetexts" NormalCitation True)
794− , ("Autocite", citation "Autocite" NormalCitation False)
795− , ("Smartcite", citation "Smartcite" NormalCitation False)
796− , ("Footcite", inNote <$> citation "Footcite" NormalCitation False)
797− , ("Parencite", citation "Parencite" NormalCitation False)
798− , ("Supercite", citation "Supercite" NormalCitation False)
799− , ("Footcitetext", inNote <$> citation "Footcitetext" NormalCitation False)
800− , ("Citeyearpar", citation "Citeyearpar" SuppressAuthor False)
801− , ("Citeyear", citation "Citeyear" SuppressAuthor False)
802− , ("Autocite*", citation "Autocite*" SuppressAuthor False)
803− , ("Cite*", citation "Cite*" SuppressAuthor False)
804− , ("Parencite*", citation "Parencite*" SuppressAuthor False)
805− , ("Textcite", citation "Textcite" AuthorInText False)
806− , ("Textcites", citation "Textcites" AuthorInText True)
807− , ("Cites", citation "Cites" NormalCitation True)
808− , ("Autocites", citation "Autocites" NormalCitation True)
809− , ("Footcites", inNote <$> citation "Footcites" NormalCitation True)
810− , ("Parencites", citation "Parencites" NormalCitation True)
811− , ("Supercites", citation "Supercites" NormalCitation True)
812− , ("Footcitetexts", inNote <$> citation "Footcitetexts" NormalCitation True)
813− , ("citetext", complexNatbibCitation NormalCitation)
814− , ("citeauthor", (try (tok *> sp *> controlSeq "citetext") *>
815− complexNatbibCitation AuthorInText)
816− <|> citation "citeauthor" AuthorInText False)
817− , ("nocite", mempty <$ (citation "nocite" NormalCitation False >>=
819 , ("hyperlink", hyperlink)
643 , ("hyperlink", hyperlink)
820 , ("hypertarget", hypertargetInline)
644 , ("hypertarget", hypertargetInline)
821 -- glossaries package
645 -- glossaries package
@@ -918,7 +742,7 @@ inlineCommands =
919lettrine :: PandocMonad m => LP m Inlines
743lettrine :: PandocMonad m => LP m Inlines
920lettrine = do
744lettrine = do
921− optional opt
745+ optional rawopt
924 return $ extractSpaces (spanWith ("",["lettrine"],[])) x <> smallcaps y
748 return $ extractSpaces (spanWith ("",["lettrine"],[])) x <> smallcaps y
@@ -1168,6 +992,16 @@ inline = (mempty <$ comment)
1168inlines :: PandocMonad m => LP m Inlines
992inlines :: PandocMonad m => LP m Inlines
1169inlines = mconcat <$> many inline
993inlines = mconcat <$> many inline
995+opt :: PandocMonad m => LP m Inlines
997+ toks <- try (sp *> bracketedToks <* sp)
998+ -- now parse the toks as inlines
1000+ parsed <- runParserT (mconcat <$> many inline) st "bracketed option" toks
1002+ Right result -> return result
1003+ Left e -> throwError $ PandocParsecError (untokenize toks) e
1171-- block elements:
1005-- block elements:
1173preamble :: PandocMonad m => LP m Blocks
1007preamble :: PandocMonad m => LP m Blocks
@@ -1261,10 +1095,6 @@ insertIncluded defaultExtension f' = do
1261 getInput >>= setInput . (tokenize f contents ++)
1095 getInput >>= setInput . (tokenize f contents ++)
1262 updateState dropLatestIncludeFile
1096 updateState dropLatestIncludeFile
1264−addMeta :: PandocMonad m => ToMetaValue a => Text -> a -> LP m ()
1265−addMeta field val = updateState $ \st ->
1266− st{ sMeta = addMetaField field val $ sMeta st }
1268authors :: PandocMonad m => LP m ()
1098authors :: PandocMonad m => LP m ()
1269authors = try $ do
1099authors = try $ do