Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mathjax #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
75 changes: 75 additions & 0 deletions lisp/muse-latex.el
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,81 @@ default Muse will add a footnote for each link."
nil))))
muse-latex-pdf-cruft))

;;; LaTeX Delimiters

(defcustom muse-latex-centered-begin-delimiters
'(("context" . "\\startformula ")
(nil . "\\["))
"An assoc list of the opening delimiters for centered math mode. The
CAR is the style and the CDR is the delimiter. NIL is the default, and
all options after the default are ignored."
:group 'muse-latex
:type '(alist :key-type sexp :value-type string))

(defcustom muse-latex-centered-end-delimiters
'(("context" . "\\endformula ")
(nil . "\\]"))
"An assoc list of the closing delimiters for centered math mode. The
CAR is the style and the CDR is the delimiter. NIL is the default, and
all options after the default are ignored."
:group 'muse-latex
:type '(alist :key-type sexp :value-type string))

(defcustom muse-latex-inline-begin-delimiters
'(("mathjax-html" . " \\( ")
("mathjax-xhtml" . " \\( ")
(nil . "$"))
"An assoc list of the opening delimiters for inline math mode. The
CAR is the style and the CDR is the delimiter. NIL is the default, and
all options after the default are ignored."
:group 'muse-latex
:type '(alist :key-type sexp :value-type string))

(defcustom muse-latex-inline-end-delimiters
'(("mathjax-html" . " \\) ")
("mathjax-xhtml" . " \\) ")
(nil . "$"))
"An assoc list of the closing delimiters for inline math mode. The
CAR is the style and the CDR is the delimiter. NIL is the default, and
all options after the default are ignored."
:group 'muse-latex
:type '(alist :key-type sexp :value-type string))


(defun muse-publish-latex-delimiters (centered begin)
"Queries the variables
`muse-latex-inline-begin-delimiters',
`muse-latex-inline-end-delimiters',
`muse-latex-centered-begin-delimiters' and
`muse-latex-centered-end-delimiters' for the correct
delimiter to insert."
(let* ((delimiter-alist (cond (centered
(if begin muse-latex-centered-begin-delimiters
muse-latex-centered-end-delimiters))
(t
(if begin muse-latex-inline-begin-delimiters
muse-latex-inline-end-delimiters))))
delim style)
(while (and
(setq style (caar delimiter-alist))
(null (setq delim (if (muse-style-derived-p style) (cdar delimiter-alist))))
(setq delimiter-alist (cdr delimiter-alist))))
(or delim (cdr (assoc nil delimiter-alist)))))

(defcustom muse-publish-latex-tag-as-is '("latex" "context" "mathjax-html" "mathjax-xhtml")
"Styles which should publish La/TeX source as is."
:type '(repeat string)
:group 'muse-latex)

(defun muse-publish-latex-tag-as-is ()
"Query the variable `muse-publish-latex-tag-as-is' if STYLE should
publish <latex> tags as literals."
(memq t
(mapcar (lambda(x) (muse-style-derived-p x)) muse-publish-latex-tag-as-is)))




;;; Register the Muse LATEX Publishers

(muse-define-style "latex"
Expand Down
18 changes: 6 additions & 12 deletions lisp/muse-latex2png.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
;;; Code

(require 'muse-publish)
(require 'muse-latex)

(defgroup muse-latex2png nil
"Publishing LaTeX formulas as PNG files."
Expand Down Expand Up @@ -209,7 +210,7 @@ See `muse-latex2png-region' for valid keys for ATTRS."
(setq attrs (cons (cons "prefix"
(concat "latex2png-" (muse-page-name)))
attrs)))
(if (or (muse-style-derived-p "latex") (muse-style-derived-p "context"))
(if (muse-publish-latex-tag-as-is)
(muse-publish-mark-read-only beg end)
(muse-latex2png-region beg end attrs)))

Expand All @@ -233,22 +234,15 @@ centered in the published output, among other things."
(looking-at (concat "[" muse-regexp-blank "]*$"))))
(prog1 t
(replace-match "")
(when (and (or (muse-style-derived-p "latex")
(muse-style-derived-p "context"))
(when (and (muse-publish-latex-tag-as-is)
(not (bobp)))
(backward-char 1)
(if (bolp)
(delete-char 1)
(forward-char 1)))
(setq beg (point)))))
(tag-beg (if centered
(if (muse-style-derived-p "context")
"\\startformula " "\\[ ")
"$"))
(tag-end (if centered
(if (muse-style-derived-p "context")
" \\stopformula" " \\]")
"$"))
(tag-beg (muse-publish-latex-delimiters centered t))
(tag-end (muse-publish-latex-delimiters centered nil))
(attrs (nconc (list (cons "prefix"
(concat "latex2png-" (muse-page-name))))
(if centered nil
Expand All @@ -257,7 +251,7 @@ centered in the published output, among other things."
(muse-insert-markup tag-beg)
(goto-char end)
(muse-insert-markup tag-end)
(if (or (muse-style-derived-p "latex") (muse-style-derived-p "context"))
(if (muse-publish-latex-tag-as-is)
(muse-publish-mark-read-only beg (point))
(muse-latex2png-region beg (point) attrs))))

Expand Down
105 changes: 105 additions & 0 deletions lisp/muse-mathjax.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
;; muse-mathjax.el --- generate MathJaX code from inline LaTeX code

;; Copyright (C) 2011
;; Free Software Foundation, Inc.

;; Author: Leo Butler <leo.butler@member.fsf.org>
;; Created: 19-Nov-2011

;; Emacs Muse is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.

;; Emacs Muse is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with Emacs Muse; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;;; MathJaX (http://www.mathjax.org/) is a Javascript application that
;;; converts LaTeX code to MathML. The syntax is needs is \( ... \)
;;; for inline math and \[ ... \] for centered math.
;;;
;;; This code provides the conversion of Muse tags <latex> and <math>
;;; for use with MathJaX.

;;; To do

;;; Code

(require 'muse-publish)
(require 'muse-html)

(defgroup muse-mathjax nil
"Support for publishing LaTeX formulas as MathJaX."
:group 'muse-publish)

(defcustom muse-mathjax-src-url
"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
"URL to source the MathJaX Javascript code."
:type 'string
:group 'muse-mathjax)

(defcustom muse-mathjax-configuration
"
tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']],
displayMath: [['$$','$$'], ['\\\\[','\\\\]']]}
"
"Configuration of the MathJaX processer. See
http://www.mathjax.org/docs/1.1/options/tex2jax.html#configure-tex2jax
for information.

This configuration information is inserted into the <head>
section of the HTML page before the link to the MathJaX page
itself. See `muse-mathjax-html-header'."
:type 'string
:group 'muse-mathjax)

(defvar muse-mathjax-html-header
(muse-replace-regexp-in-string
"<head>"
(concat "<head>\n"
"<script src=\"<lisp>muse-mathjax-src-url</lisp>\" type=\"text/javascript\"></script>\n"
"<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({
<lisp>muse-mathjax-configuration</lisp>
});
</script>")
muse-html-header)
"Header for HTML files generated with the mathjax-html
style. See `muse-mathjax-configuration' and
`muse-mathjax-src-url'.")

(defvar muse-mathjax-xhtml-header
(muse-replace-regexp-in-string
"<head>"
(concat "<head>\n"
"<script src=\"<lisp>muse-mathjax-src-url</lisp>\" type=\"text/javascript\"></script>\n"
"<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({
<lisp>muse-mathjax-configuration</lisp>
});
</script>")
muse-xhtml-header)
"Header for XHTML files generated with the mathjax-xhtml
style. See `muse-mathjax-configuration' and
`muse-mathjax-src-url'.")


(muse-derive-style "mathjax-html" "html"
:header 'muse-mathjax-html-header)
(muse-derive-style "mathjax-xhtml" "xhtml"
:header 'muse-mathjax-xhtml-header)

(defun muse-mathjax ())

(provide 'muse-mathjax)

;;; muse-mathjax.el ends here
55 changes: 55 additions & 0 deletions texi/muse.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,12 @@ Supports publishing to HTML 4.0 and HTML 4.01, Strict or Transitional.
@item xhtml
Supports publishing to XHTML 1.0 and XHTML 1.1, Strict or Transitional.

@item mathjax-html
Extension of html style to support embedding raw LaTeX code in HTML.

@item mathjax-xhtml
Extension of xhtml style to support embedding raw LaTeX code in XHTML.

@end table

@subheading Options provided
Expand Down Expand Up @@ -2532,6 +2538,23 @@ The default HTML meta charset to use if no translation is found in
The default Emacs buffer encoding to use in published files.
This will be used if no special characters are found.

@item muse-mathjax-src-url
The URL of the MathJaX Javascript source.

@item muse-mathjax-configuration
Javascript code that is passed to @code{MathJaX.Hub.Config} to configure
MathJaX at load time. By default, this sets allowed delimiters for LaTeX
code.

@item muse-mathjax-html-header
The HTML header inserted into pages published with the mathjax-html
style. By default, this is the @code{muse-html-header} with the
@code{muse-mathjax-src-url} and @code{muse-mathjax-configuration}
inserted.

@item muse-mathjax-xhtml-header
The analogue of @code{muse-mathjax-html-header} for mathjax-xhtml.

@end table

@node Ikiwiki, Journal, HTML, Publishing Styles
Expand Down Expand Up @@ -2929,6 +2952,16 @@ This can also use the @verb{|<slide>|} tag.
@item lecture-notes-pdf
Publish a PDF document of lecture notes, using the Beamer extension.

@cindex publishing styles, mathjax-html
@item mathjax-html
Publish an HTML document using the MathJaX Javascript extension to
display LaTeX in the browser.

@cindex publishing styles, mathjax-xhtml
@item mathjax-xhtml
Publish an XHTML document using the MathJaX Javascript extension to
display LaTeX in the browser.

@end table

@subheading Options provided
Expand Down Expand Up @@ -3052,6 +3085,28 @@ ignore the @verb{|<contents>|} tag.
If you don't agree with this, then set this option to non-nil,
and it will do what you expect.

@item muse-latex-centered-begin-delimiters
An alist of styles and the associated opening delimiter used when
publishing @verb{|<math>|} regions in that style. The @verb{|NIL|} style
supplies the default value of @verb{|$$|}.

@item muse-latex-centered-end-delimiters
An alist of styles and the associated closing delimiter used when
publishing @verb{|<math>|} regions in that style. The @verb{|NIL|} style
supplies the default value of @verb{|$$|}.

@item muse-latex-inline-begin-delimiters
An alist of styles and the associated opening delimiter used when
publishing @verb{|<math>|} regions in that style. The @verb{|NIL|} style
supplies the default value of @verb{|$|}.

@item muse-latex-inline-end-delimiters
An alist of styles and the associated closing delimiter used when
publishing @verb{|<math>|} regions in that style. The @verb{|NIL|} style
supplies the default value of @verb{|$|}.



@end table

@node Poem, Texinfo, LaTeX, Publishing Styles
Expand Down