Flexible Lisp Blogware. Fork for personal use. Mirrored from https://github.com/kingcons/coleslaw originally.

mathjax.lisp 1.1KB

1234567891011121314151617181920212223242526272829
  1. (defpackage :coleslaw-mathjax
  2. (:use :cl)
  3. (:export #:enable)
  4. (:import-from :coleslaw #:add-injection
  5. #:content
  6. #:index
  7. #:tag-p
  8. #:index-content))
  9. (in-package :coleslaw-mathjax)
  10. (defvar *mathjax-header* "~@[<script type=\"text/x-mathjax-config\">
  11. MathJax.Hub.Config({~A});
  12. </script>~]
  13. <script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
  14. (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
  15. (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
  16. (labels ((math-post-p (obj)
  17. ;; Would it be better to test against latex than math, here?
  18. (tag-p "math" obj))
  19. (mathjax-p (obj)
  20. (or force
  21. (etypecase obj
  22. (content (math-post-p obj))
  23. (index (some #'math-post-p (index-content obj)))))))
  24. (let ((mathjax-header (format nil *mathjax-header* config location preset)))
  25. (add-injection (list mathjax-header #'mathjax-p) :head))))