From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: MathJax beyond org-html-mathjax-options? Date: Thu, 02 Nov 2017 14:12:24 +0100 Message-ID: <87fu9w7rk7.fsf@gmx.us> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eAFIg-0000tn-G7 for emacs-orgmode@gnu.org; Thu, 02 Nov 2017 09:12:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eAFId-0006NS-83 for emacs-orgmode@gnu.org; Thu, 02 Nov 2017 09:12:50 -0400 Received: from [195.159.176.226] (port=58851 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eAFIc-0006Ke-RA for emacs-orgmode@gnu.org; Thu, 02 Nov 2017 09:12:47 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eAFII-0002S4-3q for emacs-orgmode@gnu.org; Thu, 02 Nov 2017 14:12:26 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lawrence Bottorff 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 > 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! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-html-MathJax-extensions-support.patch >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 --=-=-=--