diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2024-02-13 19:30:14 -0800 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2024-02-13 19:32:12 -0800 |
| commit | cf847b0138e07f8e0f009d7eb3f21a0e18d8708b (patch) | |
| tree | 37fb3958e15db6fe9c8961d62c7ed2db2734d8c6 | |
| parent | 02b6483b7c4a671a2c4d86ef7f292dbe0b2d4b23 (diff) | |
LaTeX reader: improve treatment of cref, Cref.
Associate with `\cref` and `\Cref` the reference-type `ref+label` and
`ref+Label`. So far we don't do anything fancy with these.
Also, associate with `\vref` `ref` instead of `ref+page`.
See #7463.
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Inline.hs | 8 | ||||
| -rw-r--r-- | test/command/1608.md | 2 | ||||
| -rw-r--r-- | test/command/refs.md | 6 |
4 files changed, 10 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index e35912adc..05f0e9891 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -114,9 +114,9 @@ parseLaTeX = do resolveRefs :: M.Map Text [Inline] -> Inline -> Inline resolveRefs labels x@(Link (ident,classes,kvs) _ _) = - case (lookup "reference-type" kvs, + case (T.takeWhile (/='+') <$> lookup "reference-type" kvs, lookup "reference" kvs) of - (Just "ref", Just lab) -> + (Just "ref", Just lab) -> -- TODO special treatment of ref+label case M.lookup lab labels of Just txt -> Link (ident,classes,kvs) txt ("#" <> lab, "") Nothing -> x diff --git a/src/Text/Pandoc/Readers/LaTeX/Inline.hs b/src/Text/Pandoc/Readers/LaTeX/Inline.hs index 3fc004524..757d0931b 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Inline.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Inline.hs @@ -337,11 +337,11 @@ refCommands :: PandocMonad m => M.Map Text (LP m Inlines) refCommands = M.fromList [ ("label", rawInlineOr "label" dolabel) , ("ref", rawInlineOr "ref" $ doref "ref") - , ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty - , ("Cref", rawInlineOr "Cref" $ doref "ref") -- from cleveref.sty - , ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty + , ("cref", rawInlineOr "cref" $ doref "ref+label") -- from cleveref.sty + , ("Cref", rawInlineOr "Cref" $ doref "ref+Label") -- from cleveref.sty + , ("vref", rawInlineOr "vref" $ doref "ref") -- from varioref.sty , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty - , ("autoref", rawInlineOr "autoref" $ doref "autoref") -- from hyperref.sty + , ("autoref", rawInlineOr "autoref" $ doref "ref+label") -- from hyperref.sty ] acronymCommands :: PandocMonad m => M.Map Text (LP m Inlines) diff --git a/test/command/1608.md b/test/command/1608.md index 77fdaf6d3..5c40d4499 100644 --- a/test/command/1608.md +++ b/test/command/1608.md @@ -129,7 +129,7 @@ These are all pretty interesting facts. , Link ( "" , [] - , [ ( "reference-type" , "ref" ) + , [ ( "reference-type" , "ref+label" ) , ( "reference" , "def:tri" ) ] ) diff --git a/test/command/refs.md b/test/command/refs.md index cf2395fb8..f54f4fa8d 100644 --- a/test/command/refs.md +++ b/test/command/refs.md @@ -28,7 +28,7 @@ Figure \cref{fig:1} , Link ( "" , [] - , [ ( "reference-type" , "ref" ) + , [ ( "reference-type" , "ref+label" ) , ( "reference" , "fig:1" ) ] ) @@ -48,7 +48,7 @@ Figure \vref{fig:1} , Link ( "" , [] - , [ ( "reference-type" , "ref+page" ) + , [ ( "reference-type" , "ref" ) , ( "reference" , "fig:1" ) ] ) @@ -66,7 +66,7 @@ Figure \vref{fig:1} [ Link ( "" , [] - , [ ( "reference-type" , "autoref" ) + , [ ( "reference-type" , "ref+label" ) , ( "reference" , "fig:flowchart" ) ] ) |
