#lang racket/base (require scribble/manual scribble/core scribble/html-properties scribble/latex-properties scriblib/render-cond racket/runtime-path setup/collects "katex-convert-unicode.rkt" "mathjax-convert-unicode.rkt" racket/list) (provide $ $$ $-html-handler $$-html-handler $-katex $$-katex $-mathjax $$-mathjax use-katex use-mathjax with-html5) ;; KaTeX does not work well with the HTML 4.01 Transitional loose DTD, ;; so we define a style modifier which replaces the prefix for HTML rendering. (define (with-html5 doc-style) (define has-html-defaults? (memf html-defaults? (style-properties doc-style))) (define new-properties (if has-html-defaults? (map (λ (s) (if (html-defaults? s) (html-defaults (path->collects-relative (collection-file-path "html5-prefix.html" "scribble-math")) (html-defaults-style-path s) (html-defaults-extra-files s)) s)) (style-properties doc-style)) (cons (html-defaults (path->collects-relative (collection-file-path "html5-prefix.html" "scribble-math")) #f '())))) (style (style-name doc-style) new-properties)) ;; Other possible sources for MathJax: ;"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" ;"http://c328740.r40.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=default" ;"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-HTML" (define-runtime-path mathjax-dir "MathJax") (define-runtime-path katex-dir "katex") #| (define mathjax-dir (path->collects-relative (collection-file-path "MathJax" "scribble-math"))) |# ;; take into account last scroll event, to avoid locking up the page ;; TODO: should actually pause the whole MathJax queue, as it still locks ;; up the browser between "processing Math" and "rendering math". ;; + set the #MathJax_Message CSS to opacity: 0.5. (define gradually-rename-texMath-to-texMathX-js #< 1000) { if (e.id == "") { e.id = "texMathElement" + pos; } e[pos++].className = "texMathX"; MathJax.Hub.Queue(["Typeset",MathJax.Hub,e.id]); MathJax.Hub.Queue(["next",o]); } else { window.setTimeout(process, 100); } } else { window.removeEventListener("scroll", scrollEventHandler); } }; o.next = function() { window.setTimeout(process, 100); } process(); })(); EOJS ) (define (load-script-string src [async-defer #f]) (string-append #<');})(); EOJS )) (define (load-style-string src) (string-append #<'); })(); EOJS )) (define load-mathjax-code (string->bytes/utf-8 ;; To avoid the need to alter the MathJax configuration, add: ;; (load-script-string "MathJax/MathJax.js?config=default"))) #;(define load-mathjax-code (string->bytes/utf-8 (string-append (load-script-string "MathJax/MathJax.js?config=default") #<bytes/utf-8 (string-append (load-style-string "katex/katex.min.css") (load-script-string "katex/katex.min.js") #<bytes/utf-8 #<