Add mathmode? option to katex-convert-unicode

This commit is contained in:
Georges Dupéron 2017-07-12 19:17:51 +02:00
parent e1f3c3daa6
commit 4386f6563d

View File

@ -8,7 +8,7 @@
(string-join (map regexp-quote literal-alternatives) "|") (string-join (map regexp-quote literal-alternatives) "|")
")")) ")"))
(define (string-replace* str sym→*) (define (string-replace* str mathmode? sym→*)
(define →* (map (λ (x) (define →* (map (λ (x)
(cons (symbol->string (car x)) (cons (symbol->string (car x))
(cadr x))) (cadr x)))
@ -17,12 +17,16 @@
(regexp-replace* (literal-alternatives→regexp (map car →*)) (regexp-replace* (literal-alternatives→regexp (map car →*))
str str
(λ (found . _) (λ (found . _)
(hash-ref hash→* found)))) (let ([replacement (hash-ref hash→* found)])
(if mathmode?
replacement
(string-append "$" replacement "$"))))))
(define (katex-convert-unicode str) (define (katex-convert-unicode str mathmode?)
(if (string? str) (if (string? str)
(string-replace* (string-replace*
str str
mathmode?
'([ "{}_0"] '([ "{}_0"]
[ "{}_1"] [ "{}_1"]
[ "{}_2"] [ "{}_2"]