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

mathjax.lisp 1.1KB

123456789101112131415161718192021222324252627282930
  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. (defgeneric mathjax-p (document)
  15. (:documentation "Test if DOCUMENT requires contains any math-tagged content.")
  16. (:method ((content content))
  17. (tag-p "math" content))
  18. (:method ((index index))
  19. (and (slot-boundp index 'content)
  20. (some #'mathjax-p (index-content index)))))
  21. (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
  22. (location "http://cdn.mathjax.org/mathjax/latest/MathJax.js"))
  23. (flet ((plugin-p (x) (or force (mathjax-p x))))
  24. (let ((mathjax-header (format nil *mathjax-header* config location preset)))
  25. (add-injection (list mathjax-header #'plugin-p) :head))))