Recently Written · git

coleslaw

Emacs mode for the "Coleslaw" site generator written in Common Lisp.

git clone https://github.com/equwal/coleslaw

Log | Files | Refs


plugins/mathjax.lisp (1094 bytes)

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 
10 (in-package :coleslaw-mathjax)
11 
12 (defvar *mathjax-header* "~@[<script type=\"text/x-mathjax-config\">
13   MathJax.Hub.Config({~A});
14 </script>~]
15 <script type=\"text/javascript\" src=\"~A~@[?config=~A~]\"></script>")
16 
17 (defgeneric mathjax-p (document)
18   (:documentation "Test if DOCUMENT requires contains any math-tagged content.")
19   (:method ((content content))
20     (tag-p "math" content))
21   (:method ((index index))
22     (and (slot-boundp index 'content)
23          (some #'mathjax-p (index-content index)))))
24 
25 (defun enable (&key force config (preset "TeX-AMS-MML_HTMLorMML")
26                  (location "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"))
27   (flet ((inject-p (x)
28            (when (or force (mathjax-p x))
29              (format nil *mathjax-header* config location preset))))
30     (add-injection #'inject-p :head)))