From 0afb48cd384ea1663f88bda32d0d149dc9a6f6c5 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Wed, 22 Sep 2021 22:33:00 -0700
Subject: HTML writer: pass through `\ref` and `\eqref`...

if MathJax is used.

Closes #7587.
---
 src/Text/Pandoc/Writers/HTML.hs | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

(limited to 'src')

diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 03d182f5e..f883bd6d8 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -1469,8 +1469,9 @@ inlineToHtml opts inline = do
       if ishtml
          then return $ preEscapedText str
          else if (f == Format "latex" || f == Format "tex") &&
-                allowsMathEnvironments (writerHTMLMathMethod opts) &&
-                isMathEnvironment str
+                 ((allowsMathEnvironments (writerHTMLMathMethod opts) &&
+                   isMathEnvironment str) ||
+                  (allowsRef (writerHTMLMathMethod opts) && isRef str))
                 then inlineToHtml opts $ Math DisplayMath str
                 else do
                   report $ InlineNotRendered inline
@@ -1602,6 +1603,9 @@ inDiv cls x = do
     (if html5 then H5.div else H.div)
                 x ! A.class_ (toValue cls)
 
+isRef :: Text -> Bool
+isRef t = "\\ref{" `T.isPrefixOf` t || "\\eqref{" `T.isPrefixOf` t
+
 isMathEnvironment :: Text -> Bool
 isMathEnvironment s = "\\begin{" `T.isPrefixOf` s &&
                          envName `elem` mathmlenvs
@@ -1641,6 +1645,10 @@ allowsMathEnvironments MathML      = True
 allowsMathEnvironments (WebTeX _)  = True
 allowsMathEnvironments _           = False
 
+allowsRef :: HTMLMathMethod -> Bool
+allowsRef (MathJax _) = True
+allowsRef _           = False
+
 -- | List of intrinsic event attributes allowed on all elements in HTML4.
 intrinsicEventsHTML4 :: [Text]
 intrinsicEventsHTML4 =
-- 
cgit v1.2.3