emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* MathJax beyond org-html-mathjax-options?
@ 2017-11-01  1:30 Lawrence Bottorff
  2017-11-02 13:12 ` Rasmus
  0 siblings, 1 reply; 4+ messages in thread
From: Lawrence Bottorff @ 2017-11-01  1:30 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]

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 org-html-mathjax-options is expandable. . . .

LB

[-- Attachment #2: Type: text/html, Size: 562 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: MathJax beyond org-html-mathjax-options?
  2017-11-01  1:30 MathJax beyond org-html-mathjax-options? Lawrence Bottorff
@ 2017-11-02 13:12 ` Rasmus
  2017-11-03 17:29   ` Lawrence Bottorff
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus @ 2017-11-02 13:12 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1348 bytes --]

Lawrence Bottorff <borgauf@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!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-MathJax-extensions-support.patch --]
[-- Type: text/x-diff, Size: 9628 bytes --]

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: MathJax beyond org-html-mathjax-options?
  2017-11-02 13:12 ` Rasmus
@ 2017-11-03 17:29   ` Lawrence Bottorff
  2017-11-03 17:40     ` Rasmus
  0 siblings, 1 reply; 4+ messages in thread
From: Lawrence Bottorff @ 2017-11-03 17:29 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode Mailinglist

[-- Attachment #1: Type: text/plain, Size: 1994 bytes --]

Bottom line: we can't expand org-html-mathjax-options to add in MathJax's
cancel.js, etc. Yes, your first "quick-and-dirty" worked just fine. Q: How
did you know how to format #+html: \(\require{cancel}\) ? Also, how does
the org world know that we're talking about loading MathJax's cancel.js? As
you all know I'm not a "developer-class" poster here, so my questions often
look dull-witted. Will try the patch once I learn a bit more diff in Emacs
lore. . . .

On Thu, Nov 2, 2017 at 9:12 AM, Rasmus <rasmus@gmx.us> wrote:

> Lawrence Bottorff <borgauf@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!
>

[-- Attachment #2: Type: text/html, Size: 2974 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: MathJax beyond org-html-mathjax-options?
  2017-11-03 17:29   ` Lawrence Bottorff
@ 2017-11-03 17:40     ` Rasmus
  0 siblings, 0 replies; 4+ messages in thread
From: Rasmus @ 2017-11-03 17:40 UTC (permalink / raw)
  To: borgauf; +Cc: emacs-orgmode

Lawrence Bottorff <borgauf@gmail.com> writes:

> Bottom line: we can't expand org-html-mathjax-options to add in MathJax's
> cancel.js, etc.

I did not say that.  With the current version, you could do it yourself by
adding (extensions "ext1.js, ..., extn.js") to org-html-mathjax-options
and changing org-html-mathjax-template to load the extensions at the right
place.  Once extensions is added to org-html-mathjax-options you should
also be able to set it in files via the #+html_mathjax keyword, but you
might have to be careful how you write it (I’m not sure space would go).
I hope this is clear enough.

> Yes, your first "quick-and-dirty" worked just fine.

> Q: How did you know how to format #+html: \(\require{cancel}\) ?

it’s in the mathjax manual,

    http://docs.mathjax.org/en/latest/tex.html?highlight=cancel#tex-and-latex-extensions

> Also, how does the org world know that we're talking about loading
>MathJax's cancel.js?

It doesn’t really.  But content after "#+html:" is only added to html
output.  From there mathjax takes over.

> As you all know I'm not a "developer-class" poster here, so my questions
> often look dull-witted.

This is a community for all Org users.  There’s mostly no numb questions.
This one certainly wasn’t.  I’d no knowledge about mathjax extensions
before reading your mail.

> Will try the patch once I learn a bit more diff in Emacs lore. . . .

Thanks.

Rasmus

-- 
And when I’m finished thinking, I have to die a lot

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-03 17:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-01  1:30 MathJax beyond org-html-mathjax-options? Lawrence Bottorff
2017-11-02 13:12 ` Rasmus
2017-11-03 17:29   ` Lawrence Bottorff
2017-11-03 17:40     ` Rasmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).