;;; org-static-mathjax.el --- Muse-like tags in Org-mode ;; ;; Author: Jan Böker ;; This file is part of GNU Emacs. ;; GNU Emacs 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 of the License, or ;; (at your option) any later version. ;; GNU Emacs 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 GNU Emacs. If not, see . ;;; Commentary: ;; This elisp code integrates Static MathJax into the ;; HTML export process of Org-mode. ;; ;; The supporting files for this package are in contrib/scripts/staticmathjax ;; Please read the README.org file in that directory for more information. ;; To use it, evaluate it on startup, add the following to your .emacs: ;; (require 'org-static-mathjax) ;; ;; You will then have to customize the following two variables: ;; - org-static-mathjax-app-ini-path ;; - org-static-mathjax-local-mathjax-path ;; ;; If xulrunner is not in your $PATH, you will also need to customize ;; org-static-mathjax-xulrunner-path. ;; ;; If everything is setup correctly, you can trigger Static MathJax on ;; export to HTML by adding the following line to your Org file: ;; #+StaticMathJax: embed-fonts:nil output-file-name:"embedded-math.html" ;; ;; You can omit either argument. ;; embed-fonts defaults to nil. If you do not specify output-file-name, ;; the exported file is overwritten with the static version. ;; ;; If embed-fonts is non-nil, the fonts are embedded directly into the ;; output file using data: URIs. ;; ;; output-file-name specifies the file name of the static version. You ;; can use any arbitrary lisp form here, for example: ;; output-file-name:(concat (file-name-sans-extension buffer-file-name) "-static.html") ;; ;; The StaticMathJax XULRunner application expects a UTF-8 encoded ;; input file. If the static version displays random characters instead ;; of your math, add the following line at the top of your Org file: ;; -*- coding: utf-8; -*- ;; ;;; Code: (defcustom org-static-mathjax-app-ini-path (or (expand-file-name "../scripts/staticmatchjax/application.ini" (file-name-directory (or load-file-name buffer-file-name))) "") "Path to \"application.ini\" of the Static MathJax XULRunner application. If you have extracted StaticMathJax to e.g. ~/.local/staticmathjax, set this to ~/.local/staticmathjax/application.ini" :type 'string) (defcustom org-static-mathjax-xulrunner-path "xulrunner" "Path to your xulrunner binary" :type 'string) (defcustom org-static-mathjax-local-mathjax-path "" "Extract the MathJax zip file somewhere on your local hard drive and specify the path here. The directory has to be writeable, as org-static-mathjax creates a temporary file there during export." :type 'string) (defvar org-static-mathjax-debug nil "If non-nil, org-static-mathjax will print some debug messages") (defun org-static-mathjax-hook-installer () "Installs org-static-mathjax-process in after-save-hook. Sets the following buffer-local variables for org-static-mathjax-process to pick up: org-static-mathjax-mathjax-path: The path to MathJax.js as used by Org HTML export org-static-mathjax-options: The string given with #+STATICMATHJAX: in the file" (let ((static-mathjax-option-string (plist-get opt-plist :static-mathjax))) (if static-mathjax-option-string (progn (set (make-local-variable 'org-static-mathjax-options) static-mathjax-option-string) (set (make-local-variable 'org-static-mathjax-mathjax-path) (nth 1 (assq 'path org-export-html-mathjax-options))) (let ((mathjax-options (plist-get opt-plist :mathjax))) (if mathjax-options (if (string-match "\\