@@ -180,7 +180,7 @@ satisfyTok f = tokenPrim (T.unpack . untoken) updatePos matcher
180180 updatePos spos _ [] = spos
181181
182182anyControlSeq :: PandocMonad m => LP m Tok
183−anyControlSeq = satisfyTok isCtrlSeq <* spaces
183+anyControlSeq = satisfyTok isCtrlSeq <* optional sp
184184 where isCtrlSeq (Tok _ CtrlSeq _) = True
185185 isCtrlSeq _ = False
186186
@@ -404,10 +404,16 @@ inlineCommand' = try $ do
404404 lookupListDefault raw names inlineCommands
405405
406406tok :: PandocMonad m => LP m Inlines
407−tok = try $ grouped inline <|> inlineCommand'
408− <|> (str . T.unpack . untoken) <$> anyTok
409− -- note: this will swallow a whole word in cases
410− -- where latex would only consider one letter (TODO?)
407+tok = try $ grouped inline <|> inlineCommand' <|> singleChar
408+ where singleChar = do
409+ Tok (lin,col) toktype t <- satisfyTok (tokTypeIn [Word, Symbol])
410+ if T.length t > 1
411+ then do
412+ let (t1, t2) = (T.take 1 t, T.drop 1 t)
413+ inp <- getInput
414+ setInput $ (Tok (lin, col + 1) toktype t2) : inp
415+ return $ str (T.unpack t1)
416+ else return $ str (T.unpack t)
411417
412418opt :: PandocMonad m => LP m Inlines
413419opt = bracketed inline
@@ -416,7 +422,7 @@ rawopt :: PandocMonad m => LP m Text
416422rawopt = do
417423 symbol '['
418424 inner <- untokenize <$> manyTill anyTok (symbol ']')
419− spaces
425+ optional sp
420426 return $ "[" <> inner <> "]"
421427
422428skipopts :: PandocMonad m => LP m ()
@@ -448,31 +454,6 @@ withRaw parser = do
448454
449455inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
450456inlineCommands = M.fromList
451− [ ("emph", extractSpaces emph <$> tok)
452− ]
453−
454−isBlockCommand :: Text -> Bool
455−isBlockCommand s =
456− s `M.member` (blockCommands :: M.Map Text (LP PandocPure Blocks))
457−
458−lookupListDefault :: (Ord k) => v -> [k] -> M.Map k v -> v
459−lookupListDefault d = (fromMaybe d .) . lookupList
460− where
461− lookupList l m = msum $ map (`M.lookup` m) l
462−
463−{-
464−rawInlineOr :: PandocMonad m => String -> LP m Inlines -> LP m Inlines
465−rawInlineOr name' fallback = do
466− parseRaw <- extensionEnabled Ext_raw_tex <$> getOption readerExtensions
467− if parseRaw
468− then rawInline "latex" <$> getRawCommand name'
469− else fallback
470−
471−isBlockCommand :: String -> Bool
472−isBlockCommand s = s `M.member` (blockCommands :: M.Map String (LP PandocPure Blocks))
473−
474−inlineCommands :: PandocMonad m => M.Map String (LP m Inlines)
475−inlineCommands = M.fromList $
476457 [ ("emph", extractSpaces emph <$> tok)
477458 , ("textit", extractSpaces emph <$> tok)
478459 , ("textsl", extractSpaces emph <$> tok)
@@ -495,15 +476,15 @@ inlineCommands = M.fromList $
495476 , ("dots", lit "…")
496477 , ("mdots", lit "…")
497478 , ("sim", lit "~")
498− , ("label", rawInlineOr "label" (inBrackets <$> tok))
499− , ("ref", rawInlineOr "ref" (inBrackets <$> tok))
500− , ("textgreek", tok)
501− , ("sep", lit ",")
502− , ("cref", rawInlineOr "cref" (inBrackets <$> tok)) -- from cleveref.sty
503− , ("(", mathInline $ manyTill anyChar (try $ string "\\)"))
504− , ("[", mathDisplay $ manyTill anyChar (try $ string "\\]"))
505− , ("ensuremath", mathInline braced)
506− , ("texorpdfstring", (\_ x -> x) <$> tok <*> tok)
479+-- , ("label", rawInlineOr "label" (inBrackets <$> tok))
480+-- , ("ref", rawInlineOr "ref" (inBrackets <$> tok))
481+-- , ("textgreek", tok)
482+-- , ("sep", lit ",")
483+-- , ("cref", rawInlineOr "cref" (inBrackets <$> tok)) -- from cleveref.sty
484+-- , ("(", mathInline $ manyTill anyChar (try $ string "\\)"))
485+-- , ("[", mathDisplay $ manyTill anyChar (try $ string "\\]"))
486+-- , ("ensuremath", mathInline braced)
487+-- , ("texorpdfstring", (\_ x -> x) <$> tok <*> tok)
507488 , ("P", lit "¶")
508489 , ("S", lit "§")
509490 , ("$", lit "$")
@@ -540,125 +521,149 @@ inlineCommands = M.fromList $
540521 , ("copyright", lit "©")
541522 , ("textasciicircum", lit "^")
542523 , ("textasciitilde", lit "~")
543− , ("H", try $ tok >>= accent hungarumlaut)
544− , ("`", option (str "`") $ try $ tok >>= accent grave)
545− , ("'", option (str "'") $ try $ tok >>= accent acute)
546− , ("^", option (str "^") $ try $ tok >>= accent circ)
547− , ("~", option (str "~") $ try $ tok >>= accent tilde)
548− , ("\"", option (str "\"") $ try $ tok >>= accent umlaut)
549− , (".", option (str ".") $ try $ tok >>= accent dot)
550− , ("=", option (str "=") $ try $ tok >>= accent macron)
551− , ("c", option (str "c") $ try $ tok >>= accent cedilla)
552− , ("v", option (str "v") $ try $ tok >>= accent hacek)
553− , ("u", option (str "u") $ try $ tok >>= accent breve)
554− , ("i", lit "i")
555− , ("\\", linebreak <$ (optional (bracketed inline) *> spaces'))
556− , (",", lit "\8198")
557− , ("@", pure mempty)
558− , (" ", lit "\160")
559− , ("ps", pure $ str "PS." <> space)
560− , ("TeX", lit "TeX")
561− , ("LaTeX", lit "LaTeX")
562− , ("bar", lit "|")
563− , ("textless", lit "<")
564− , ("textgreater", lit ">")
565− , ("thanks", note <$> grouped block)
566− , ("footnote", note <$> grouped block)
567− , ("verb", doverb)
568− , ("lstinline", dolstinline)
569− , ("Verb", doverb)
570− , ("url", (unescapeURL <$> braced) >>= \url ->
571− pure (link url "" (str url)))
572− , ("href", (unescapeURL <$> braced <* optional sp) >>= \url ->
573− tok >>= \lab ->
574− pure (link url "" lab))
575− , ("includegraphics", do options <- option [] keyvals
576− src <- unescapeURL . removeDoubleQuotes <$> braced
577− mkImage options src)
578− , ("enquote", enquote)
579− , ("cite", citation "cite" NormalCitation False)
580− , ("Cite", citation "Cite" NormalCitation False)
581− , ("citep", citation "citep" NormalCitation False)
582− , ("citep*", citation "citep*" NormalCitation False)
583− , ("citeal", citation "citeal" NormalCitation False)
584− , ("citealp", citation "citealp" NormalCitation False)
585− , ("citealp*", citation "citealp*" NormalCitation False)
586− , ("autocite", citation "autocite" NormalCitation False)
587− , ("smartcite", citation "smartcite" NormalCitation False)
588− , ("footcite", inNote <$> citation "footcite" NormalCitation False)
589− , ("parencite", citation "parencite" NormalCitation False)
590− , ("supercite", citation "supercite" NormalCitation False)
591− , ("footcitetext", inNote <$> citation "footcitetext" NormalCitation False)
592− , ("citeyearpar", citation "citeyearpar" SuppressAuthor False)
593− , ("citeyear", citation "citeyear" SuppressAuthor False)
594− , ("autocite*", citation "autocite*" SuppressAuthor False)
595− , ("cite*", citation "cite*" SuppressAuthor False)
596− , ("parencite*", citation "parencite*" SuppressAuthor False)
597− , ("textcite", citation "textcite" AuthorInText False)
598− , ("citet", citation "citet" AuthorInText False)
599− , ("citet*", citation "citet*" AuthorInText False)
600− , ("citealt", citation "citealt" AuthorInText False)
601− , ("citealt*", citation "citealt*" AuthorInText False)
602− , ("textcites", citation "textcites" AuthorInText True)
603− , ("cites", citation "cites" NormalCitation True)
604− , ("autocites", citation "autocites" NormalCitation True)
605− , ("footcites", inNote <$> citation "footcites" NormalCitation True)
606− , ("parencites", citation "parencites" NormalCitation True)
607− , ("supercites", citation "supercites" NormalCitation True)
608− , ("footcitetexts", inNote <$> citation "footcitetexts" NormalCitation True)
609− , ("Autocite", citation "Autocite" NormalCitation False)
610− , ("Smartcite", citation "Smartcite" NormalCitation False)
611− , ("Footcite", citation "Footcite" NormalCitation False)
612− , ("Parencite", citation "Parencite" NormalCitation False)
613− , ("Supercite", citation "Supercite" NormalCitation False)
614− , ("Footcitetext", inNote <$> citation "Footcitetext" NormalCitation False)
615− , ("Citeyearpar", citation "Citeyearpar" SuppressAuthor False)
616− , ("Citeyear", citation "Citeyear" SuppressAuthor False)
617− , ("Autocite*", citation "Autocite*" SuppressAuthor False)
618− , ("Cite*", citation "Cite*" SuppressAuthor False)
619− , ("Parencite*", citation "Parencite*" SuppressAuthor False)
620− , ("Textcite", citation "Textcite" AuthorInText False)
621− , ("Textcites", citation "Textcites" AuthorInText True)
622− , ("Cites", citation "Cites" NormalCitation True)
623− , ("Autocites", citation "Autocites" NormalCitation True)
624− , ("Footcites", citation "Footcites" NormalCitation True)
625− , ("Parencites", citation "Parencites" NormalCitation True)
626− , ("Supercites", citation "Supercites" NormalCitation True)
627− , ("Footcitetexts", inNote <$> citation "Footcitetexts" NormalCitation True)
628− , ("citetext", complexNatbibCitation NormalCitation)
629− , ("citeauthor", (try (tok *> optional sp *> controlSeq "citetext") *>
630− complexNatbibCitation AuthorInText)
631− <|> citation "citeauthor" AuthorInText False)
632− , ("nocite", mempty <$ (citation "nocite" NormalCitation False >>=
633− addMeta "nocite"))
634− , ("hypertarget", braced >> tok)
635− -- siuntix
636− , ("SI", dosiunitx)
637− -- hyphenat
638− , ("bshyp", lit "\\\173")
639− , ("fshyp", lit "/\173")
640− , ("dothyp", lit ".\173")
641− , ("colonhyp", lit ":\173")
642− , ("hyp", lit "-")
643− , ("nohyphens", tok)
644− , ("textnhtt", ttfamily)
645− , ("nhttfamily", ttfamily)
646− -- fontawesome
647− , ("faCheck", lit "\10003")
648− , ("faClose", lit "\10007")
649− ] ++ map ignoreInlines
650− -- these commands will be ignored unless --parse-raw is specified,
651− -- in which case they will appear as raw latex blocks:
652− [ "index"
653− , "hspace"
654− , "vspace"
655− , "newpage"
656− , "clearpage"
657− , "pagebreak"
524+-- , ("H", try $ tok >>= accent hungarumlaut)
525+-- , ("`", option (str "`") $ try $ tok >>= accent grave)
526+-- , ("'", option (str "'") $ try $ tok >>= accent acute)
527+-- , ("^", option (str "^") $ try $ tok >>= accent circ)
528+-- , ("~", option (str "~") $ try $ tok >>= accent tilde)
529+-- , ("\"", option (str "\"") $ try $ tok >>= accent umlaut)
530+-- , (".", option (str ".") $ try $ tok >>= accent dot)
531+-- , ("=", option (str "=") $ try $ tok >>= accent macron)
532+-- , ("c", option (str "c") $ try $ tok >>= accent cedilla)
533+-- , ("v", option (str "v") $ try $ tok >>= accent hacek)
534+-- , ("u", option (str "u") $ try $ tok >>= accent breve)
535+-- , ("i", lit "i")
536+-- , ("\\", linebreak <$ (optional (bracketed inline) *> spaces'))
537+-- , (",", lit "\8198")
538+-- , ("@", pure mempty)
539+-- , (" ", lit "\160")
540+-- , ("ps", pure $ str "PS." <> space)
541+-- , ("TeX", lit "TeX")
542+-- , ("LaTeX", lit "LaTeX")
543+-- , ("bar", lit "|")
544+-- , ("textless", lit "<")
545+-- , ("textgreater", lit ">")
546+-- , ("thanks", note <$> grouped block)
547+-- , ("footnote", note <$> grouped block)
548+-- , ("verb", doverb)
549+-- , ("lstinline", dolstinline)
550+-- , ("Verb", doverb)
551+-- , ("url", (unescapeURL <$> braced) >>= \url ->
552+-- pure (link url "" (str url)))
553+-- , ("href", (unescapeURL <$> braced <* optional sp) >>= \url ->
554+-- tok >>= \lab ->
555+-- pure (link url "" lab))
556+-- , ("includegraphics", do options <- option [] keyvals
557+-- src <- unescapeURL . removeDoubleQuotes <$> braced
558+-- mkImage options src)
559+-- , ("enquote", enquote)
560+-- , ("cite", citation "cite" NormalCitation False)
561+-- , ("Cite", citation "Cite" NormalCitation False)
562+-- , ("citep", citation "citep" NormalCitation False)
563+-- , ("citep*", citation "citep*" NormalCitation False)
564+-- , ("citeal", citation "citeal" NormalCitation False)
565+-- , ("citealp", citation "citealp" NormalCitation False)
566+-- , ("citealp*", citation "citealp*" NormalCitation False)
567+-- , ("autocite", citation "autocite" NormalCitation False)
568+-- , ("smartcite", citation "smartcite" NormalCitation False)
569+-- , ("footcite", inNote <$> citation "footcite" NormalCitation False)
570+-- , ("parencite", citation "parencite" NormalCitation False)
571+-- , ("supercite", citation "supercite" NormalCitation False)
572+-- , ("footcitetext", inNote <$> citation "footcitetext" NormalCitation False)
573+-- , ("citeyearpar", citation "citeyearpar" SuppressAuthor False)
574+-- , ("citeyear", citation "citeyear" SuppressAuthor False)
575+-- , ("autocite*", citation "autocite*" SuppressAuthor False)
576+-- , ("cite*", citation "cite*" SuppressAuthor False)
577+-- , ("parencite*", citation "parencite*" SuppressAuthor False)
578+-- , ("textcite", citation "textcite" AuthorInText False)
579+-- , ("citet", citation "citet" AuthorInText False)
580+-- , ("citet*", citation "citet*" AuthorInText False)
581+-- , ("citealt", citation "citealt" AuthorInText False)
582+-- , ("citealt*", citation "citealt*" AuthorInText False)
583+-- , ("textcites", citation "textcites" AuthorInText True)
584+-- , ("cites", citation "cites" NormalCitation True)
585+-- , ("autocites", citation "autocites" NormalCitation True)
586+-- , ("footcites", inNote <$> citation "footcites" NormalCitation True)
587+-- , ("parencites", citation "parencites" NormalCitation True)
588+-- , ("supercites", citation "supercites" NormalCitation True)
589+-- , ("footcitetexts", inNote <$> citation "footcitetexts" NormalCitation True)
590+-- , ("Autocite", citation "Autocite" NormalCitation False)
591+-- , ("Smartcite", citation "Smartcite" NormalCitation False)
592+-- , ("Footcite", citation "Footcite" NormalCitation False)
593+-- , ("Parencite", citation "Parencite" NormalCitation False)
594+-- , ("Supercite", citation "Supercite" NormalCitation False)
595+-- , ("Footcitetext", inNote <$> citation "Footcitetext" NormalCitation False)
596+-- , ("Citeyearpar", citation "Citeyearpar" SuppressAuthor False)
597+-- , ("Citeyear", citation "Citeyear" SuppressAuthor False)
598+-- , ("Autocite*", citation "Autocite*" SuppressAuthor False)
599+-- , ("Cite*", citation "Cite*" SuppressAuthor False)
600+-- , ("Parencite*", citation "Parencite*" SuppressAuthor False)
601+-- , ("Textcite", citation "Textcite" AuthorInText False)
602+-- , ("Textcites", citation "Textcites" AuthorInText True)
603+-- , ("Cites", citation "Cites" NormalCitation True)
604+-- , ("Autocites", citation "Autocites" NormalCitation True)
605+-- , ("Footcites", citation "Footcites" NormalCitation True)
606+-- , ("Parencites", citation "Parencites" NormalCitation True)
607+-- , ("Supercites", citation "Supercites" NormalCitation True)
608+-- , ("Footcitetexts", inNote <$> citation "Footcitetexts" NormalCitation True)
609+-- , ("citetext", complexNatbibCitation NormalCitation)
610+-- , ("citeauthor", (try (tok *> optional sp *> controlSeq "citetext") *>
611+-- complexNatbibCitation AuthorInText)
612+-- <|> citation "citeauthor" AuthorInText False)
613+-- , ("nocite", mempty <$ (citation "nocite" NormalCitation False >>=
614+-- addMeta "nocite"))
615+-- , ("hypertarget", braced >> tok)
616+-- -- siuntix
617+-- , ("SI", dosiunitx)
618+-- -- hyphenat
619+-- , ("bshyp", lit "\\\173")
620+-- , ("fshyp", lit "/\173")
621+-- , ("dothyp", lit ".\173")
622+-- , ("colonhyp", lit ":\173")
623+-- , ("hyp", lit "-")
624+-- , ("nohyphens", tok)
625+-- , ("textnhtt", ttfamily)
626+-- , ("nhttfamily", ttfamily)
627+-- -- fontawesome
628+-- , ("faCheck", lit "\10003")
629+-- , ("faClose", lit "\10007")
630+-- ] ++ map ignoreInlines
631+-- -- these commands will be ignored unless --parse-raw is specified,
632+-- -- in which case they will appear as raw latex blocks:
633+-- [ "index"
634+-- , "hspace"
635+-- , "vspace"
636+-- , "newpage"
637+-- , "clearpage"
638+-- , "pagebreak"
658639 ]
659640
641+ttfamily :: PandocMonad m => LP m Inlines
642+ttfamily = (code . stringify . toList) <$> tok
660643
661−-}
644+rawInlineOr :: PandocMonad m => String -> LP m Inlines -> LP m Inlines
645+rawInlineOr name' fallback = do
646+ parseRaw <- extensionEnabled Ext_raw_tex <$> getOption readerExtensions
647+ if parseRaw
648+ then rawInline "latex" <$> getRawCommand name'
649+ else fallback
650+
651+getRawCommand :: PandocMonad m => String -> LP m String
652+getRawCommand name' = do
653+ (_, rawargs) <- withRaw
654+ (many (try (optional sp *> opt)) *>
655+ option "" (try (optional sp *> dimenarg)) *>
656+ many braced)
657+ return $ '\\' : name' ++ T.unpack (untokenize rawargs)
658+
659+isBlockCommand :: Text -> Bool
660+isBlockCommand s =
661+ s `M.member` (blockCommands :: M.Map Text (LP PandocPure Blocks))
662+
663+lookupListDefault :: (Ord k) => v -> [k] -> M.Map k v -> v
664+lookupListDefault d = (fromMaybe d .) . lookupList
665+ where
666+ lookupList l m = msum $ map (`M.lookup` m) l
662667
663668inline :: PandocMonad m => LP m Inlines
664669inline = (mempty <$ comment)