2011-04-26 13:52:15 -04:00
|
|
|
(defpackage :coleslaw-mathjax
|
2012-09-15 17:39:00 -04:00
|
|
|
(:use :cl)
|
2012-09-20 18:33:29 -04:00
|
|
|
(:export #:enable)
|
2012-09-15 17:39:00 -04:00
|
|
|
(:import-from :coleslaw #:add-injection
|
2013-01-02 13:04:20 -05:00
|
|
|
#:content
|
2012-09-15 17:39:00 -04:00
|
|
|
#:index
|
2013-01-02 13:04:20 -05:00
|
|
|
#:content-tags
|
2012-09-15 17:39:00 -04:00
|
|
|
#:index-posts))
|
2011-04-19 13:36:17 -04:00
|
|
|
|
2011-04-26 13:52:15 -04:00
|
|
|
(in-package :coleslaw-mathjax)
|
|
|
|
|
2013-04-03 18:27:30 +02:00
|
|
|
(defvar *mathjax-config-header* "<script type=\"text/x-mathjax-config\">
|
2012-08-22 22:39:41 -04:00
|
|
|
MathJax.Hub.Config({
|
2013-04-03 20:05:04 +02:00
|
|
|
~A
|
2012-08-22 22:39:41 -04:00
|
|
|
});
|
2011-04-26 13:52:15 -04:00
|
|
|
</script>
|
2013-04-03 18:27:30 +02:00
|
|
|
")
|
2011-04-26 13:52:15 -04:00
|
|
|
|
2013-04-03 20:05:04 +02:00
|
|
|
(defvar *default-mathjax-config* "tex2jax: {inlineMath: [['$$','$$']]}")
|
|
|
|
|
2013-04-03 18:27:30 +02:00
|
|
|
(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")
|
2013-04-03 20:05:04 +02:00
|
|
|
(config "TeX-AMS-MML_HTMLorMML")
|
|
|
|
(mathjax-config *default-mathjax-config*))
|
2013-01-02 13:04:20 -05:00
|
|
|
(labels ((math-post-p (obj)
|
|
|
|
(member "math" (content-tags obj) :test #'string=))
|
|
|
|
(mathjax-p (obj)
|
2013-04-03 18:27:30 +02:00
|
|
|
(or force
|
|
|
|
(etypecase obj
|
|
|
|
(content (math-post-p obj))
|
|
|
|
(index (some #'math-post-p (index-posts obj)))))))
|
|
|
|
|
|
|
|
(let ((mathjax-header
|
|
|
|
(concatenate 'string
|
2013-04-03 20:10:10 +02:00
|
|
|
(if mathjax-config (format nil *mathjax-config-header* mathjax-config) "")
|
2013-04-03 18:27:30 +02:00
|
|
|
(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))))
|