@@ -56,6 +56,7 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
5656 ArgSpec (..), Tok (..), TokType (..))
5757import Text.Pandoc.Readers.LaTeX.Parsing
5858import Text.Pandoc.Readers.LaTeX.Accent (accentCommands)
59+import Text.Pandoc.Readers.LaTeX.Citation (citationCommands, cites)
5960import Text.Pandoc.Readers.LaTeX.Table (tableEnvironments)
6061import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
6162 babelLangToBCP47)
@@ -169,7 +170,7 @@ rawLaTeXInline = do
169170 let toks = tokenize "source" inp
170171 raw <- snd <$>
171172 ( rawLaTeXParser toks True
172− (mempty <$ (controlSeq "input" >> skipMany opt >> braced))
173+ (mempty <$ (controlSeq "input" >> skipMany rawopt >> braced))
173174 inlines
174175 <|> rawLaTeXParser toks True (inlineEnvironment <|> inlineCommand')
175176 inlines
@@ -311,7 +312,7 @@ blockquote :: PandocMonad m => Bool -> Maybe Text -> LP m Blocks
311312blockquote cvariant mblang = do
312313 citepar <- if cvariant
313314 then (\xs -> para (cite xs mempty))
314− <$> cites NormalCitation False
315+ <$> cites inline NormalCitation False
315316 else option mempty $ para <$> bracketed inline
316317 let lang = mblang >>= babelLangToBCP47
317318 let langdiv = case lang of
@@ -425,116 +426,6 @@ pDollarsMath n = do
425426 else mzero
426427 _ -> (tk :) <$> pDollarsMath n
427428
428−-- citations
429−
430−addPrefix :: [Inline] -> [Citation] -> [Citation]
431−addPrefix p (k:ks) = k {citationPrefix = p ++ citationPrefix k} : ks
432−addPrefix _ _ = []
433−
434−addSuffix :: [Inline] -> [Citation] -> [Citation]
435−addSuffix s ks@(_:_) =
436− let k = last ks
437− in init ks ++ [k {citationSuffix = citationSuffix k ++ s}]
438−addSuffix _ _ = []
439−
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
453− , citationHash = 0
454− , citationNoteNum = 0
455− }
456− return $ addPrefix pre $ addSuffix suf $ map conv keys
457−
458−citationLabel :: PandocMonad m => LP m Text
459−citationLabel = do
460− sp
461− untokenize <$>
462− (many1 (satisfyTok isWordTok <|> symbolIn bibtexKeyChar)
463− <* sp
464− <* optional (symbol ',')
465− <* sp)
466− where bibtexKeyChar = ".:;?!`'()/*@_+=-&[]" :: [Char]
467−
468−cites :: PandocMonad m => CitationMode -> Bool -> LP m [Citation]
469−cites mode multi = try $ do
470− cits <- if multi
471− then 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
480− case tempCits of
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)]
485− _ -> return [[]]
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
491− [] -> []
492− _ -> map (\a -> a {citationMode = mode}) cs
493− where mprenote (k:ks) = (k:ks) ++ [Space]
494− mprenote _ = mempty
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
500− _ -> mpn
501− in addPrefix mpnfinal (k:ks)
502− addMprenote _ _ = []
503− addMpostnote = addSuffix . mpostnote
504−
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)
509−
510−handleCitationPart :: Inlines -> [Citation]
511−handleCitationPart ils =
512− let isCite Cite{} = True
513− isCite _ = False
514− (pref, rest) = break isCite (toList ils)
515− in case rest of
516− (Cite cs _:suff) -> addPrefix pref $ addSuffix suff cs
517− _ -> []
518−
519−complexNatbibCitation :: PandocMonad m => CitationMode -> LP m Inlines
520−complexNatbibCitation mode = try $ do
521− (cs, raw) <-
522− withRaw $ concat <$> do
523− bgroup
524− items <- mconcat <$>
525− many1 (notFollowedBy (symbol ';') >> inline)
526− `sepBy1` symbol ';'
527− egroup
528− return $ map handleCitationPart items
529− case cs of
530− [] -> mzero
531− (c:cits) -> return $ cite (c{ citationMode = mode }:cits)
532− (rawInline "latex" $ "\\citetext" <> untokenize raw)
533−
534−inNote :: Inlines -> Inlines
535−inNote ils =
536− note $ para $ ils <> str "."
537−
538429inlineCommand' :: PandocMonad m => LP m Inlines
539430inlineCommand' = try $ do
540431 Tok _ (CtrlSeq name) cmd <- anyControlSeq
@@ -553,19 +444,6 @@ inlineCommand' = try $ do
553444tok :: PandocMonad m => LP m Inlines
554445tok = tokWith inline
555446
556−opt :: PandocMonad m => LP m Inlines
557−opt = do
558− toks <- try (sp *> bracketedToks <* sp)
559− -- now parse the toks as inlines
560− st <- getState
561− parsed <- runParserT (mconcat <$> many inline) st "bracketed option" toks
562− case parsed of
563− Right result -> return result
564− Left e -> throwError $ PandocParsecError (untokenize toks) e
565−
566−paropt :: PandocMonad m => LP m Inlines
567−paropt = parenWrapped inline
568−
569447inBrackets :: Inlines -> Inlines
570448inBrackets x = str "[" <> x <> str "]"
571449
@@ -629,6 +507,7 @@ inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
629507inlineCommands =
630508 M.union inlineLanguageCommands $
631509 M.union (accentCommands tok) $
510+ M.union (citationCommands inline) $
632511 M.fromList
633512 [ ("emph", extractSpaces emph <$> tok)
634513 , ("textit", extractSpaces emph <$> tok)
@@ -703,7 +582,7 @@ inlineCommands =
703582 , ("/", pure mempty) -- italic correction
704583 , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState
705584 guard $ not inTableCell
706− optional opt
585+ optional rawopt
707586 spaces))
708587 , (",", lit "\8198")
709588 , ("@", pure mempty)
@@ -761,61 +640,6 @@ inlineCommands =
761640 , ("proofname", doTerm Translations.Proof)
762641 , ("glossaryname", doTerm Translations.Glossary)
763642 , ("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 >>=
818− addMeta "nocite"))
819643 , ("hyperlink", hyperlink)
820644 , ("hypertarget", hypertargetInline)
821645 -- glossaries package
@@ -918,7 +742,7 @@ inlineCommands =
918742
919743lettrine :: PandocMonad m => LP m Inlines
920744lettrine = do
921− optional opt
745+ optional rawopt
922746 x <- tok
923747 y <- tok
924748 return $ extractSpaces (spanWith ("",["lettrine"],[])) x <> smallcaps y
@@ -1168,6 +992,16 @@ inline = (mempty <$ comment)
1168992inlines :: PandocMonad m => LP m Inlines
1169993inlines = mconcat <$> many inline
1170994
995+opt :: PandocMonad m => LP m Inlines
996+opt = do
997+ toks <- try (sp *> bracketedToks <* sp)
998+ -- now parse the toks as inlines
999+ st <- getState
1000+ parsed <- runParserT (mconcat <$> many inline) st "bracketed option" toks
1001+ case parsed of
1002+ Right result -> return result
1003+ Left e -> throwError $ PandocParsecError (untokenize toks) e
1004+
11711005-- block elements:
11721006
11731007preamble :: PandocMonad m => LP m Blocks
@@ -1261,10 +1095,6 @@ insertIncluded defaultExtension f' = do
12611095 getInput >>= setInput . (tokenize f contents ++)
12621096 updateState dropLatestIncludeFile
12631097
1264−addMeta :: PandocMonad m => ToMetaValue a => Text -> a -> LP m ()
1265−addMeta field val = updateState $ \st ->
1266− st{ sMeta = addMetaField field val $ sMeta st }
1267−
12681098authors :: PandocMonad m => LP m ()
12691099authors = try $ do
12701100 bgroup