From 5a4c0d6a8cf7e15ec1d871fee641ffcc063ef89a Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Tue, 7 Nov 2017 13:05:06 -0800
Subject: [PATCH] Deprecated ancient HTML math methods.

`--latexmathml`,
`--gladtex`,
`--mimetex`,
`--jsmath`
---
 MANUAL.txt             | 19 ++++++-------
 src/Text/Pandoc/App.hs | 62 ++++++++++++++++++++++++++----------------
 2 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/MANUAL.txt b/MANUAL.txt
index fc461847c..588750f1e 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -1124,21 +1124,18 @@ of the following options.
 
 `-m` [*URL*], `--latexmathml`[`=`*URL*]
 
-:   Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
+:   *Deprecated.*
+    Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
     TeX math will be displayed between `$` or `$$` characters and put in
     `<span>` tags with class `LaTeX`. The LaTeXMathML JavaScript will then
     change it to MathML. Note that currently only Firefox and Safari
     (and select e-book readers) natively support MathML.
-    To insert a link to a local copy of the `LaTeXMathML.js` script,
-    provide a *URL*. If no *URL* is provided, the contents of the
-    script will be inserted directly into the HTML header, preserving
-    portability at the price of efficiency. If you plan to use math on
-    several pages, it is much better to link to a copy of the script,
-    so it can be cached.
+    To insert a link the `LaTeXMathML.js` script, provide a *URL*.
 
 `--jsmath`[`=`*URL*]
 
-:   Use [jsMath] (the predecessor of MathJax) to display embedded TeX
+:   *Deprecated.*
+    Use [jsMath] (the predecessor of MathJax) to display embedded TeX
     math in HTML output. TeX math will be put inside `<span>` tags
     (for inline math) or `<div>` tags (for display math) with class
     `math` and rendered by the jsMath script. The *URL* should point to
@@ -1149,7 +1146,8 @@ of the following options.
 
 `--gladtex`
 
-:   Enclose TeX math in `<eq>` tags in HTML output.  The resulting HTML
+:   *Deprecated.*
+    Enclose TeX math in `<eq>` tags in HTML output.  The resulting HTML
     can then be processed by [gladTeX] to produce images of the typeset
     formulas and an HTML file with links to these images.
     So, the procedure is:
@@ -1160,7 +1158,8 @@ of the following options.
 
 `--mimetex`[`=`*URL*]
 
-:   Render TeX math using the [mimeTeX] CGI script, which generates an
+:   *Deprecated.*
+    Render TeX math using the [mimeTeX] CGI script, which generates an
     image for each TeX formula. This should work in all browsers. If
     *URL* is not specified, it is assumed that the script is at
     `/cgi-bin/mimetex.cgi`.
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index e82ccf3f0..d9924d3a1 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -1401,29 +1401,12 @@ options =
                   (\opt -> return opt { optCiteMethod = Biblatex }))
                  "" -- "Use biblatex cite commands in LaTeX output"
 
-    , Option "m" ["latexmathml", "asciimathml"]
-                 (OptArg
-                  (\arg opt ->
-                      return opt { optHTMLMathMethod = LaTeXMathML arg })
-                  "URL")
-                 "" -- "Use LaTeXMathML script in html output"
-
     , Option "" ["mathml"]
                  (NoArg
                   (\opt ->
                       return opt { optHTMLMathMethod = MathML }))
                  "" -- "Use mathml for HTML math"
 
-    , Option "" ["mimetex"]
-                 (OptArg
-                  (\arg opt -> do
-                      let url' = case arg of
-                                      Just u  -> u ++ "?"
-                                      Nothing -> "/cgi-bin/mimetex.cgi?"
-                      return opt { optHTMLMathMethod = WebTeX url' })
-                  "URL")
-                 "" -- "Use mimetex for HTML math"
-
     , Option "" ["webtex"]
                  (OptArg
                   (\arg opt -> do
@@ -1432,12 +1415,6 @@ options =
                   "URL")
                  "" -- "Use web service for HTML math"
 
-    , Option "" ["jsmath"]
-                 (OptArg
-                  (\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
-                  "URL")
-                 "" -- "Use jsMath for HTML math"
-
     , Option "" ["mathjax"]
                  (OptArg
                   (\arg opt -> do
@@ -1446,6 +1423,7 @@ options =
                       return opt { optHTMLMathMethod = MathJax url'})
                   "URL")
                  "" -- "Use MathJax for HTML math"
+
     , Option "" ["katex"]
                  (OptArg
                   (\arg opt ->
@@ -1455,9 +1433,38 @@ options =
                   "URL")
                   "" -- Use KaTeX for HTML Math
 
+    , Option "m" ["latexmathml", "asciimathml"]
+                 (OptArg
+                  (\arg opt -> do
+                      deprecatedOption "--latexmathml"
+                      return opt { optHTMLMathMethod = LaTeXMathML arg })
+                  "URL")
+                 "" -- "Use LaTeXMathML script in html output"
+
+    , Option "" ["mimetex"]
+                 (OptArg
+                  (\arg opt -> do
+                      deprecatedOption "--mimetex"
+                      let url' = case arg of
+                                      Just u  -> u ++ "?"
+                                      Nothing -> "/cgi-bin/mimetex.cgi?"
+                      return opt { optHTMLMathMethod = WebTeX url' })
+                  "URL")
+                 "" -- "Use mimetex for HTML math"
+
+    , Option "" ["jsmath"]
+                 (OptArg
+                  (\arg opt -> do
+                      deprecatedOption "--jsmath"
+                      return opt { optHTMLMathMethod = JsMath arg})
+                  "URL")
+                 "" -- "Use jsMath for HTML math"
+
     , Option "" ["gladtex"]
                  (NoArg
-                  (\opt -> return opt { optHTMLMathMethod = GladTeX }))
+                  (\opt -> do
+                      deprecatedOption "--gladtex"
+                      return opt { optHTMLMathMethod = GladTeX }))
                  "" -- "Use gladtex for HTML math"
 
     , Option "" ["abbreviations"]
@@ -1655,3 +1662,10 @@ splitField s =
 
 baseWriterName :: String -> String
 baseWriterName = takeWhile (\c -> c /= '+' && c /= '-')
+
+deprecatedOption :: String -> IO ()
+deprecatedOption o =
+  runIO (report $ Deprecated o "") >>=
+    \r -> case r of
+       Right () -> return ()
+       Left e   -> E.throwIO e