Merge pull request #20 from woudshoo/mathjax-improvements

Mathjax improvements
This commit is contained in:
Brit Butler 2013-04-04 06:03:26 -07:00
commit cd8b9f8d2c
2 changed files with 41 additions and 12 deletions

View file

@ -22,6 +22,16 @@
**Example**: ```(mathjax)```
### Options
`:force`, when specified with a true value, will force the inclusion of MathJax, even if no posts are tagged "math". Default value is `nil`.
`:mathjax-url` specifies the location of the `MathJax.js`. The default value is `"http://cdn.mathjax.org/mathjax/latest/MathJax.js"`. This is useful if you want to force a specific value of MathJax, or if you have a local copy of MathJax and want to use that version.
`:config` allows the specification of the config parameter of `MathJax.js`. The default value is `"TeX-AMS-MML_HTMLorMML"`.
`:mathjax-config` allows specifying the content of the `...` in a `MathJax.Hub.Config ({ ... });` section. The default is `tex2jax: {inlineMath: [['$$','$$']]}`, which allows display equations to be enclosed in `$$`. If a `nil` argument is supplied the whole `<script>` section containing the `MathJax.Hub.Config` will be omitted.
## ReStructuredText
**Description**: Some people really like [ReStructuredText](http://docutils.sourceforge.net/rst.html). Who knows why? But it only took one method to add, so yeah! Just create a post with ```format: rst``` and the plugin will do the rest.

View file

@ -9,22 +9,41 @@
(in-package :coleslaw-mathjax)
(defvar *mathjax-header* "<script type=\"text/x-mathjax-config\">
(defvar *mathjax-config-header* "<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$$','$$']]
}
~A
});
</script>
<script type=\"text/javascript\"
src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\">
</script>")
")
(defun enable ()
(defvar *default-mathjax-config* "tex2jax: {inlineMath: [['$$','$$']]}")
(defvar *mathjax-load-header-no-config* "<script type=\"text/javascript\"
src=\"~A\">
</script>
")
(defvar *mathjax-load-header-with-config* "<script type=\"text/javascript\"
src=\"~A?config=~A\">
</script>
")
(defun enable (&key force
(mathjax-url "http://cdn.mathjax.org/mathjax/latest/MathJax.js")
(config "TeX-AMS-MML_HTMLorMML")
(mathjax-config *default-mathjax-config*))
(labels ((math-post-p (obj)
(member "math" (content-tags obj) :test #'string=))
(mathjax-p (obj)
(etypecase obj
(content (math-post-p obj))
(index (some #'math-post-p (index-posts obj))))))
(add-injection (list *mathjax-header* #'mathjax-p) :head)))
(or force
(etypecase obj
(content (math-post-p obj))
(index (some #'math-post-p (index-posts obj)))))))
(let ((mathjax-header
(concatenate 'string
(if mathjax-config (format nil *mathjax-config-header* mathjax-config) "")
(if config
(format nil *mathjax-load-header-with-config* mathjax-url config)
(format nil *mathjax-load-header-no-config* mathjax-url)))))
(add-injection (list mathjax-header #'mathjax-p) :head))))