From 4386f6563d0e74cf3b60124fd11924e7efd4aad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 12 Jul 2017 19:17:51 +0200 Subject: [PATCH] Add mathmode? option to katex-convert-unicode --- katex-convert-unicode.rkt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/katex-convert-unicode.rkt b/katex-convert-unicode.rkt index 76868a7e5..71c9dd123 100644 --- a/katex-convert-unicode.rkt +++ b/katex-convert-unicode.rkt @@ -8,7 +8,7 @@ (string-join (map regexp-quote literal-alternatives) "|") ")")) -(define (string-replace* str sym→*) +(define (string-replace* str mathmode? sym→*) (define →* (map (λ (x) (cons (symbol->string (car x)) (cadr x))) @@ -17,12 +17,16 @@ (regexp-replace* (literal-alternatives→regexp (map car →*)) str (λ (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) (string-replace* str + mathmode? '([₀ "{}_0"] [₁ "{}_1"] [₂ "{}_2"]