From 229bddbaed66a476ebed588853a0250cfe68fdcf Mon Sep 17 00:00:00 2001 From: Rasmus 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 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 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 " @@ -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