git.iko.soy/typeable/pandoc
on master help sign in
Put content of \ref, \label commands into span… (#3639)
2845ab5schrieveslaach
src/Text/Pandoc/Readers/LaTeX.hs+17−3
@@ -1165,11 +1165,13 @@ inlineCommands = M.fromList $
1165 , ("dots", lit "…")
1165 , ("dots", lit "…")
1166 , ("mdots", lit "…")
1166 , ("mdots", lit "…")
1167 , ("sim", lit "~")
1167 , ("sim", lit "~")
1168− , ("label", rawInlineOr "label" (inBrackets <$> tok))
1169− , ("ref", rawInlineOr "ref" (inBrackets <$> tok))
1170 , ("textgreek", tok)
1168 , ("textgreek", tok)
1171 , ("sep", lit ",")
1169 , ("sep", lit ",")
1172− , ("cref", rawInlineOr "cref" (inBrackets <$> tok)) -- from cleveref.sty
1170+ , ("label", rawInlineOr "label" dolabel)
1171+ , ("ref", rawInlineOr "ref" $ doref "ref")
1172+ , ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty
1173+ , ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty
1174+ , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty
1173 , ("(", mathInline . toksToString <$> manyTill anyTok (controlSeq ")"))
1175 , ("(", mathInline . toksToString <$> manyTill anyTok (controlSeq ")"))
1174 , ("[", mathDisplay . toksToString <$> manyTill anyTok (controlSeq "]"))
1176 , ("[", mathDisplay . toksToString <$> manyTill anyTok (controlSeq "]"))
1175 , ("ensuremath", mathInline . toksToString <$> braced)
1177 , ("ensuremath", mathInline . toksToString <$> braced)
@@ -1443,6 +1445,18 @@ treatAsInline = Set.fromList
1443 , "pagebreak"
1445 , "pagebreak"
1444 ]
1446 ]
1445
1447
1448+dolabel :: PandocMonad m => LP m Inlines
1449+dolabel = do
1450+ v <- braced
1451+ return $ spanWith ("",[],[("label", toksToString v)])
1452+ $ inBrackets $ str $ toksToString v
1453+
1454+doref :: PandocMonad m => String -> LP m Inlines
1455+doref cls = do
1456+ v <- braced
1457+ return $ spanWith ("",[],[("reference-type", cls), ("reference", toksToString v)])
1458+ $ inBrackets $ str $ toksToString v
1459+
1446lookupListDefault :: (Show k, Ord k) => v -> [k] -> M.Map k v -> v
1460lookupListDefault :: (Show k, Ord k) => v -> [k] -> M.Map k v -> v
1447lookupListDefault d = (fromMaybe d .) . lookupList
1461lookupListDefault d = (fromMaybe d .) . lookupList
1448 where lookupList l m = msum $ map (`M.lookup` m) l
1462 where lookupList l m = msum $ map (`M.lookup` m) l
test/command/refs.mdnew file+54
@@ -0,0 +1,54 @@
1+```
2+% pandoc -f latex -t native
3+Figure \ref{fig:1}
4+^D
5+[Para [Str "Figure",Space,Span ("",[],[("reference-type","ref"),("reference","fig:1")]) [Str "[fig:1]"]]]
6+```
7+
8+```
9+% pandoc -f latex -t native
10+Figure \cref{fig:1}
11+^D
12+[Para [Str "Figure",Space,Span ("",[],[("reference-type","ref"),("reference","fig:1")]) [Str "[fig:1]"]]]
13+```
14+
15+```
16+% pandoc -f latex -t native
17+Figure \vref{fig:1}
18+^D
19+[Para [Str "Figure",Space,Span ("",[],[("reference-type","ref+page"),("reference","fig:1")]) [Str "[fig:1]"]]]
20+```
21+
22+```
23+% pandoc -f latex -t native
24+Accuracy~\eqref{eq:Accuracy} is the proportion, measuring true results among all results.
25+
26+\begin{equation}
27+ \label{eq:Accuracy}
28+ Accuracy = \frac{t_p + t_n}{t_p + f_p + f_n + t_n}
29+\end{equation}
30+^D
31+[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."]
32+,Para [Math DisplayMath "\\label{eq:Accuracy}\n Accuracy = \\frac{t_p + t_n}{t_p + f_p + f_n + t_n}"]]
33+```
34+
35+```
36+% pandoc -f latex -t native
37+\begin{figure}
38+ \includegraphics{command/SVG_logo.svg}
39+ \caption{Logo}
40+ \label{fig:Logo}
41+\end{figure}
42+
43+Figure \ref{fig:Logo} illustrated the SVG logo
44+^D
45+[Para [Image ("",[],[]) [Str "Logo",Span ("",[],[("label","fig:Logo")]) []] ("command/SVG_logo.svg","fig:")]
46+,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"]]
47+```
48+
49+```
50+% pandoc -f latex -t native
51+\label{section} Section \ref{section}
52+^D
53+[Para [Span ("",[],[("label","section")]) [Str "[section]"],Space,Str "Section",Space,Span ("",[],[("reference-type","ref"),("reference","section")]) [Str "[section]"]]]
54+```