mathjax-convert-unicode, shortened javascript which loads MathJax so that it is easier to compare for removal (since we unfortunately cannot set its ID).

This commit is contained in:
Georges Dupéron 2017-07-21 02:47:46 +02:00
parent fbb7f162a0
commit d4e21dff28
3 changed files with 116 additions and 93 deletions

View File

@ -8,6 +8,7 @@
racket/runtime-path
setup/collects
"katex-convert-unicode.rkt"
"mathjax-convert-unicode.rkt"
racket/list)
(provide $
@ -114,13 +115,11 @@ EOJS
(define (load-style-string src)
(string-append
#<<EOJS
(function() {
document.write('<link rel="stylesheet" href="
(function() {document.write('<link rel="stylesheet" href="
EOJS
src
#<<EOJS
" />');
})();
" />');})();
EOJS
))

View File

@ -1,7 +1,8 @@
#lang at-exp racket/base
(require racket/string)
(provide katex-convert-unicode)
(provide katex-convert-unicode
string-replace*)
(define (literal-alternatives→regexp literal-alternatives)
(string-append "("
@ -22,96 +23,98 @@
replacement
(string-append "$" replacement "$"))))))
(define (katex-convert-unicode str mathmode?)
(define (katex-convert-unicode str mathmode? [more-sym→* '()])
(define sym→*
`([ "{}_0"]
[ "{}_1"]
[ "{}_2"]
[ "{}_3"]
[ "{}_4"]
[ "{}_5"]
[ "{}_6"]
[ "{}_7"]
[ "{}_8"]
[ "{}_9"]
[ "{}_i"]
[ "{}_j"]
[ "{}_k"]
[ "{}_l"]
[ "{}_m"]
[ "{}_n"]
[ "{}_o"]
[ "{}_x"]
[ "{}^0"]
[¹ "{}^1"]
[² "{}^2"]
[³ "{}^3"]
[ "{}^4"]
[ "{}^5"]
[ "{}^6"]
[ "{}^7"]
[ "{}^8"]
[ "{}^9"]
[ "{}^i"]
[ʲ "{}^j"]
[ "{}^k"]
[ˡ "{}^l"]
[ "{}^m"]
[ "{}^n"]
[ "{}^o"]
[ "\\subseteq{}" "\\ensuremath{\\subseteq}"]
[ "\\subset{}" "\\ensuremath{\\subset}"]
[ "\\supseteq{}" "\\ensuremath{\\supseteq}"]
[ "\\supset{}" "\\ensuremath{\\supset}"]
[ "\\rightarrow{}" "\\ensuremath{\\rightarrow}"]
[ "\\Rightarrow{}" "\\ensuremath{\\Rightarrow}"]
[ "\\leftarrow{}" "\\ensuremath{\\leftarrow}"]
[ "\\Leftarrow{}" "\\ensuremath{\\Leftarrow}"]
[ "\\leftrightarrow{}" "\\ensuremath{\\leftrightarrow}"]
[ "\\Leftrightarrow{}" "\\ensuremath{\\Leftrightarrow}"]
;; Partially extracted from my .XCompose generator
[ñ "\\tilde{n}" "{\\ifmmode\\tilde{n}\\else\\~{n}\\fi}"]
[Ñ "\\tilde{N}" "{\\ifmmode\\tilde{N}\\else\\~{N}\\fi}"]
[ "\\star{}" "\\ensuremath{\\star}"]
[ "\\ddot{\\star}}" "\\ensuremath{\\ddot{\\star}}"]
[ "^*" "^*"]
[ "\\langle{}" "\\ensuremath{\\mathsmaller{\\raisemath{.15ex}{\\langle}}}"]
[ "\\rangle{}" "\\ensuremath{\\mathsmaller{\\raisemath{.15ex}{\\rangle}}}"]
[ "\\cdots{}"]
[ "\\vdots{}"]
[ "\\iddots{}"]
[ "\\ddots{}"]
[ "\\mathbin{+\\mkern-6.5mu+}" "\\ensuremath{\\mathbin{+\\mkern-6.5mu+}}"]
[ "\\emptyset{}" "\\ensuremath{\\emptyset}"]
[ı⃗ "\\vec{\\i}}" "\\ensuremath{\\vec{\\i}"]
[ "\\oplus{}" "\\ensuremath{\\oplus}"]
[ "\\ominus{}" "\\ensuremath{\\ominus}"]
[ "\\Cup{}" "\\ensuremath{\\Cup}"]
;[ₗ "\\ensuremath{_{l}}"]
[ "::"]
[Λ "\\Lambda{}" "\\ensuremath{\\Lambda}"]
[ "\\forall{}"]
[ "\\exists{}"]
[ "\\equiv{}"]
[ "\\not\\equiv{}"]
[ "\\ldots{}"]
[ "\\cdots{}"]
[ "\\uddots{}"] ;; or \iddots from package mathdots, see http://tex.stackexchange.com/a/17650
[ "\\ddots{}"]
[ "\\notni{}"]
[ "\\mathcal{E}"]
[ "\\bullet{}"]
[ "'"]
[ "''"]
[ "'''"]
[ "''''"]
[ "\\bigcup{}"]
[ "\\bigcap{}"]
[ "\\bigwedge{}"]
[ "\\bigvee{}"]
[± "\\pm{}"]
))
(if (string? str)
(string-replace*
str
mathmode?
`([ "{}_0"]
[ "{}_1"]
[ "{}_2"]
[ "{}_3"]
[ "{}_4"]
[ "{}_5"]
[ "{}_6"]
[ "{}_7"]
[ "{}_8"]
[ "{}_9"]
[ "{}_i"]
[ "{}_j"]
[ "{}_k"]
[ "{}_l"]
[ "{}_m"]
[ "{}_n"]
[ "{}_o"]
[ "{}_x"]
[ "{}^0"]
[¹ "{}^1"]
[² "{}^2"]
[³ "{}^3"]
[ "{}^4"]
[ "{}^5"]
[ "{}^6"]
[ "{}^7"]
[ "{}^8"]
[ "{}^9"]
[ "{}^i"]
[ʲ "{}^j"]
[ "{}^k"]
[ˡ "{}^l"]
[ "{}^m"]
[ "{}^n"]
[ "{}^o"]
[ "\\subseteq{}" "\\ensuremath{\\subseteq}"]
[ "\\subset{}" "\\ensuremath{\\subset}"]
[ "\\supseteq{}" "\\ensuremath{\\supseteq}"]
[ "\\supset{}" "\\ensuremath{\\supset}"]
[ "\\rightarrow{}" "\\ensuremath{\\rightarrow}"]
[ "\\Rightarrow{}" "\\ensuremath{\\Rightarrow}"]
[ "\\leftarrow{}" "\\ensuremath{\\leftarrow}"]
[ "\\Leftarrow{}" "\\ensuremath{\\Leftarrow}"]
[ "\\leftrightarrow{}" "\\ensuremath{\\leftrightarrow}"]
[ "\\Leftrightarrow{}" "\\ensuremath{\\Leftrightarrow}"]
;; Partially extracted from my .XCompose generator
[ñ "\\tilde{n}" "{\\ifmmode\\tilde{n}\\else\\~{n}\\fi}"]
[Ñ "\\tilde{N}" "{\\ifmmode\\tilde{N}\\else\\~{N}\\fi}"]
[ "\\star{}" "\\ensuremath{\\star}"]
[ "\\ddot{\\star}}" "\\ensuremath{\\ddot{\\star}}"]
[ "^*" "^*"]
[ "\\langle{}" "\\ensuremath{\\mathsmaller{\\raisemath{.15ex}{\\langle}}}"]
[ "\\rangle{}" "\\ensuremath{\\mathsmaller{\\raisemath{.15ex}{\\rangle}}}"]
[ "\\cdots{}"]
[ "\\vdots{}"]
[ "\\iddots{}"]
[ "\\ddots{}"]
[ "\\mathbin{+\\mkern-6.5mu+}" "\\ensuremath{\\mathbin{+\\mkern-6.5mu+}}"]
[ "\\emptyset{}" "\\ensuremath{\\emptyset}"]
[ı⃗ "\\vec{\\i}}" "\\ensuremath{\\vec{\\i}"]
[ "\\oplus{}" "\\ensuremath{\\oplus}"]
[ "\\ominus{}" "\\ensuremath{\\ominus}"]
[ "\\Cup{}" "\\ensuremath{\\Cup}"]
;[ₗ "\\ensuremath{_{l}}"]
[ "::"]
[Λ "\\Lambda{}" "\\ensuremath{\\Lambda}"]
[ "\\forall{}"]
[ "\\exists{}"]
[ "\\equiv{}"]
[ "\\not\\equiv{}"]
[ "\\ldots{}"]
[ "\\cdots{}"]
[ "\\uddots{}"] ;; or \iddots from package mathdots, see http://tex.stackexchange.com/a/17650
[ "\\ddots{}"]
[ "\\notni{}"]
[ "\\mathcal{E}"]
[ "\\bullet{}"]
[ "'"]
[ "''"]
[ "'''"]
[ "''''"]
[ "\\bigcup{}"]
[ "\\bigcap{}"]
[ "\\bigwedge{}"]
[ "\\bigvee{}"]
[± "\\pm{}"]
))
(append more-sym→* sym→*))
str))

View File

@ -0,0 +1,21 @@
#lang at-exp racket/base
(require racket/string
scriblib/render-cond
"katex-convert-unicode.rkt")
(provide mathjax-convert-unicode)
(define (mathjax-convert-unicode str* mathmode?)
(define more-sym→*
`([ ,(string-append
"\\ifmathjax{\\mathrel{{\\raise0.9mu{::}\\hspace{-4mu}=}}}"
"\\iflatex{\\Coloneqq}")]
[ "\\in{}"]
[κ "\\kappa"]
[ "{}^+"]
[ "{}^-"]
;; TODO:
[ "\\ifmathjax{\\unicode{x2272}}\\iflatex{}"]
[ "\\ifmathjax{\\unicode{x2273}}\\iflatex{}"]
))
(katex-convert-unicode str* mathmode? more-sym→*))