Lawrence Bottorff <borg...@gmail.com> writes: > I'm trying to get a typical Latex strikethrough with MathJax in an HTML > export, i.e., \cancel{thing} puts line through "thing". This > <http://docs.mathjax.org/en/latest/tex.html#cancel> tells me how. But I > don't know how to include this MathJax markup in an org file for HTML > export. If I forego MathJax -- i.e., #+OPTIONS: tex:dvipng instead > of #+OPTIONS: tex:t -- \cancel works, but I need to use MathJax. It doesn't > look like orhg-html-mathjax-options is expandable. . . .
For now this works for me: #+html: \(\require{cancel}\) \begin{equation} \cancel{x = 1} \end{equation} Cf. http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-extensions You could also autoload the extension, cf. https://github.com/mathjax/MathJax/blob/master/test/sample-autoload.html That being said, I don’t think extensions were available at the time #+HTML_MATHJAX was introduced. We could add extension support, but the questions would be whether to add them to #+HTML_MATHJAX or make a new keyword, e.g. #+HTML_MATHJAX_EXTENSIONS: ext1 ext2 ... extN I guess it would default to the "autoload-all" extension. One issue is that some of them have configuration options, like "noError". If you want, you can try the attached patch. Rasmus -- Vote for proprietary math!
>From 229bddbaed66a476ebed588853a0250cfe68fdcf Mon Sep 17 00:00:00 2001 From: Rasmus <ras...@gmx.us> Date: Thu, 2 Nov 2017 13:59:17 +0100 Subject: [PATCH] ox-html: MathJax extensions support * lisp/ox-html.el (org-html-mathjax-options): (org-html-mathjax-template): (org-html--build-mathjax-config): Add MathJax extensions support. * doc/org.texi (HTML Specific export settings): (Math formatting in HTML export): Mention #+HTML_MATHJAX_EXTENSIONS. --- doc/org.texi | 12 +++++++++- lisp/ox-html.el | 73 +++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 16 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 77da6d335..6ac22aff9 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -11626,6 +11626,12 @@ Options for MathJax (@code{org-html-mathjax-options}). MathJax is used to typeset @LaTeX{} math in HTML documents. @xref{Math formatting in HTML export}, for an example. +@item HTML_MATHJAX_EXTENSIONS +@cindex #+HTML_MATHJAX_EXTENSIONS +@vindex org-html-mathjax-options +Extensions for MathJax (@code{org-html-mathjax-options}). This can be used +to e.g. add additional macro support to MathJax. + @item HTML_HEAD @cindex #+HTML_HEAD @vindex org-html-head @@ -11947,9 +11953,13 @@ options can be configured via @code{org-html-mathjax-options}, or in the buffer. For example, with the following settings, @smallexample #+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler +#+HTML_MATHJAX: cancel.js noErrors.js @end smallexample equation labels will be displayed on the left margin and equations will be -five ems from the left margin. +five ems from the left margin. In addition, it loads the two MathJax +extensions @samp{cancel.js} and @samp{noErrors.js}@footnote{See +@uref{http://docs.mathjax.org/en/latest/tex.html#tex-extensions, TeX and +LaTeX extensions} in the @uref{http://docs.mathjax.org, MathJax manual} to learn about extensions.}. @noindent See the docstring of @code{org-html-mathjax-options} for all supported variables. The MathJax diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 1c3dd8090..4f9e69fdf 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -121,6 +121,7 @@ (:html-link-home "HTML_LINK_HOME" nil org-html-link-home) (:html-link-up "HTML_LINK_UP" nil org-html-link-up) (:html-mathjax "HTML_MATHJAX" nil "" space) + (:html-mathjax-extensions "HTML_MATHJAX_EXTENSIONS" nil "" space) (:html-postamble nil "html-postamble" org-html-postamble) (:html-preamble nil "html-preamble" org-html-preamble) (:html-head "HTML_HEAD" nil org-html-head newline) @@ -1168,7 +1169,8 @@ See `format-time-string' for more information on its components." (indent "0em") (multlinewidth "85%") (tagindent ".8em") - (tagside "right")) + (tagside "right") + (extensions ("autoload-all.js"))) "Options for MathJax setup. Alist of the following elements. All values are strings. @@ -1190,23 +1192,28 @@ autonumber How to number equations. Valid values are \"None\", tagindent The amount tags are indented. tagside Which side to show tags/labels on. Valid values are \"left\" and \"right\" +extensions Which extensions to load. See http://docs.mathjax.org/en/latest/tex.html#tex-extensions You can also customize this for each buffer, using something like #+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler +#+HTML_MATHJAX_EXTENSIONS: colors noErrors For further information about MathJax options, see the MathJax documentation: http://docs.mathjax.org/" :group 'org-export-html - :package-version '(Org . "8.3") + :package-version '(Org . "9.2") :type '(list :greedy t (list :tag "path (the path from where to load MathJax.js)" (const :format " " path) (string)) (list :tag "scale (scaling for the displayed math)" (const :format " " scale) (string)) (list :tag "align (alignment of displayed equations)" - (const :format " " align) (string)) + (const :format " " align) + (choice (const "left") + (const "right") + (const "center"))) (list :tag "font (used to display math)" (const :format " " font) (choice (const "TeX") @@ -1230,11 +1237,39 @@ For further information about MathJax options, see the MathJax documentation: (list :tag "multlinewidth (width to use for the multline environment)" (const :format " " multlinewidth) (string)) (list :tag "tagindent (the indentation of tags from left or right)" - (const :format " " tagindent) (string)) + (const :format " " tagindent) (string)) (list :tag "tagside (location of tags)" (const :format " " tagside) (choice (const "left") - (const "right"))))) + (const "right"))) + (list :tag "extensions (loaded extensions)" + (const :format " " extensions) + (set + (const :tag "Autoload-all: autoload all extensions if needed" "autoload-all.js") + (const :tag "Action: access to the MathML <maction> element" "action.js") + (const :tag "AMSMath: AMS math environments and macros" "AMSmath.js") + (const :tag "AMSsymbols: macros for accessing the AMS symbol fonts" + "AMSsymbols.js") + (const :tag "AMScd: CD environment for commutative diagrams" "AMScd.js") + (const :tag "Autobold: auto-adds \\\\boldsymbol to bold sections" "autobold.js") + (const :tag "Begingroup: provides a mechanism for localizing macro defintions" + "begingroup.js") + (const :tag "Cancel: macros for various strikeouts in math environments" + "cancel.js") + (const :tag "Color: mimics the LaTeX color package" + "color.js") + (const :tag "Enclose: access to the MathML <menclose> element for adding boxes" + "enclose.js") + (const :tag "Extpfeil: adds more macros for producing extensible arrows" + "extpfeil.js") + (const :tag "HTML: access to HTML features like styles, classes, IDs and links" + "HTML.js") ; TODO: check name + (const :tag "mhchem: implements LaTeX mhchem package macros" "mhchem.js") + (const :tag "noErrors: prevents TeX error messages from being displayed" + "noErrors.js") + (const :tag "noUndefined: undefined control sequences shown as their macro names" + "noUndefined.js") + (repeat :tag "Others" :inline t string))))) (defcustom org-html-mathjax-template "<script type=\"text/x-mathjax-config\"> @@ -1243,9 +1278,9 @@ For further information about MathJax options, see the MathJax documentation: displayIndent: \"%INDENT\", \"HTML-CSS\": { scale: %SCALE, - linebreaks: { automatic: \"%LINEBREAKS\" }, - webFont: \"%FONT\" - }, + linebreaks: { automatic: \"%LINEBREAKS\" }, + webFont: \"%FONT\" + }, SVG: {scale: %SCALE, linebreaks: { automatic: \"%LINEBREAKS\" }, font: \"%FONT\"}, @@ -1253,7 +1288,8 @@ For further information about MathJax options, see the MathJax documentation: TeX: { equationNumbers: {autoNumber: \"%AUTONUMBER\"}, MultLineWidth: \"%MULTLINEWIDTH\", TagSide: \"%TAGSIDE\", - TagIndent: \"%TAGINDENT\" + TagIndent: \"%TAGINDENT\", + extensions: [\"%EXTENSIONS\"] } }); </script> @@ -1904,19 +1940,26 @@ INFO is a plist used as a communication channel." (when (and (memq (plist-get info :with-latex) '(mathjax t)) (org-element-map (plist-get info :parse-tree) '(latex-fragment latex-environment) #'identity info t nil t)) - (let ((template (plist-get info :html-mathjax-template)) - (options (plist-get info :html-mathjax-options)) - (in-buffer (or (plist-get info :html-mathjax) ""))) + (let* ((template (plist-get info :html-mathjax-template)) + (options (plist-get info :html-mathjax-options)) + (in-buffer-extensions (plist-get info :html-mathjax-extensions)) + (extensions-string (when (org-string-nw-p in-buffer-extensions) + (format " extensions: (%s)" in-buffer-extensions))) + (in-buffer (concat (or (plist-get info :html-mathjax) "") " " + (or extensions-string "")))) (dolist (e options (org-element-normalize-string template)) (let ((name (car e)) (val (nth 1 e))) - (when (string-match (concat "\\<" (symbol-name name) ":") in-buffer) + (when (string-match (format "\\<%s:" name) in-buffer) (setq val (car (read-from-string (substring in-buffer (match-end 0)))))) - (unless (stringp val) (setq val (format "%s" val))) (while (string-match (concat "%" (upcase (symbol-name name))) template) - (setq template (replace-match val t t template)))))))) + (setq template (replace-match (cond + ((listp val) (mapconcat 'symbol-name val ", ")) + ((stringp val) val) + (t (format "%s" val))) + t t template)))))))) (defun org-html-format-spec (info) "Return format specification for preamble and postamble. -- 2.15.0