diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 284dce2bc..498e97b8c 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1165,11 +1165,13 @@ inlineCommands = M.fromList $ , ("dots", lit "…") , ("mdots", lit "…") , ("sim", lit "~") - , ("label", rawInlineOr "label" (inBrackets <$> tok)) - , ("ref", rawInlineOr "ref" (inBrackets <$> tok)) , ("textgreek", tok) , ("sep", lit ",") - , ("cref", rawInlineOr "cref" (inBrackets <$> tok)) -- from cleveref.sty + , ("label", rawInlineOr "label" dolabel) + , ("ref", rawInlineOr "ref" $ doref "ref") + , ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty + , ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty + , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty , ("(", mathInline . toksToString <$> manyTill anyTok (controlSeq ")")) , ("[", mathDisplay . toksToString <$> manyTill anyTok (controlSeq "]")) , ("ensuremath", mathInline . toksToString <$> braced) @@ -1443,6 +1445,18 @@ treatAsInline = Set.fromList , "pagebreak" ] +dolabel :: PandocMonad m => LP m Inlines +dolabel = do + v <- braced + return $ spanWith ("",[],[("label", toksToString v)]) + $ inBrackets $ str $ toksToString v + +doref :: PandocMonad m => String -> LP m Inlines +doref cls = do + v <- braced + return $ spanWith ("",[],[("reference-type", cls), ("reference", toksToString v)]) + $ inBrackets $ str $ toksToString v + lookupListDefault :: (Show k, Ord k) => v -> [k] -> M.Map k v -> v lookupListDefault d = (fromMaybe d .) . lookupList where lookupList l m = msum $ map (`M.lookup` m) l diff --git a/test/command/refs.md b/test/command/refs.md new file mode 100644 index 000000000..d933235d7 --- /dev/null +++ b/test/command/refs.md @@ -0,0 +1,54 @@ +``` +% pandoc -f latex -t native +Figure \ref{fig:1} +^D +[Para [Str "Figure",Space,Span ("",[],[("reference-type","ref"),("reference","fig:1")]) [Str "[fig:1]"]]] +``` + +``` +% pandoc -f latex -t native +Figure \cref{fig:1} +^D +[Para [Str "Figure",Space,Span ("",[],[("reference-type","ref"),("reference","fig:1")]) [Str "[fig:1]"]]] +``` + +``` +% pandoc -f latex -t native +Figure \vref{fig:1} +^D +[Para [Str "Figure",Space,Span ("",[],[("reference-type","ref+page"),("reference","fig:1")]) [Str "[fig:1]"]]] +``` + +``` +% pandoc -f latex -t native +Accuracy~\eqref{eq:Accuracy} is the proportion, measuring true results among all results. + +\begin{equation} + \label{eq:Accuracy} + Accuracy = \frac{t_p + t_n}{t_p + f_p + f_n + t_n} +\end{equation} +^D +[Para [Str "Accuracy\160",Span ("",[],[("reference-type","eqref"),("reference","eq:Accuracy")]) [Str "[eq:Accuracy]"],Space,Str "is",Space,Str "the",Space,Str "proportion,",Space,Str "measuring",Space,Str "true",Space,Str "results",Space,Str "among",Space,Str "all",Space,Str "results."] +,Para [Math DisplayMath "\\label{eq:Accuracy}\n Accuracy = \\frac{t_p + t_n}{t_p + f_p + f_n + t_n}"]] +``` + +``` +% pandoc -f latex -t native +\begin{figure} + \includegraphics{command/SVG_logo.svg} + \caption{Logo} + \label{fig:Logo} +\end{figure} + +Figure \ref{fig:Logo} illustrated the SVG logo +^D +[Para [Image ("",[],[]) [Str "Logo",Span ("",[],[("label","fig:Logo")]) []] ("command/SVG_logo.svg","fig:")] +,Para [Str "Figure",Space,Span ("",[],[("reference-type","ref"),("reference","fig:Logo")]) [Str "[fig:Logo]"],Space,Str "illustrated",Space,Str "the",Space,Str "SVG",Space,Str "logo"]] +``` + +``` +% pandoc -f latex -t native +\label{section} Section \ref{section} +^D +[Para [Span ("",[],[("label","section")]) [Str "[section]"],Space,Str "Section",Space,Span ("",[],[("reference-type","ref"),("reference","section")]) [Str "[section]"]]] +```