From 8afdc71a76ce4248ebc63f65b4adf3dc94425dc7 Mon Sep 17 00:00:00 2001 From: Tim Bradshaw Date: Tue, 3 Dec 2019 19:50:13 +0000 Subject: [PATCH] Simplified MathJax Rather than generating script tags, this now simply wraps suitable delimiters around the maths, which MathJax will then find. This is essentially because I could not work out how to make the script tags work with MatJax 3. In fact I can't work out how the script tags ever worked: there doesn't seem to be any mention of embedding maths this way even for MathJax 2: all the focus is on using delimiters which MathJax looks for. In both MathJax 2 and 3 this makes the output look nicer: using the script approach seems to result in maths which, unless you apply additional styling, is blue, while this approach results in maths which is just ordinary. This change - only changes the output when using MathJax; - makes the output simpler in that case; - makes the formatted output better-looking I think; - works with at least MathJax 2 as well as 3. --- markdown/markdown.scrbl | 3 +-- markdown/parse.rkt | 6 ++---- markdown/test.rkt | 6 ++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/markdown/markdown.scrbl b/markdown/markdown.scrbl index 3774ae5..74c0c68 100644 --- a/markdown/markdown.scrbl +++ b/markdown/markdown.scrbl @@ -234,8 +234,7 @@ Markdown Extra} and @item{Support for math-jax expressions --- inline within @litchar{\\(} and @litchar{\\)} delimiters and display within @litchar{\\[} and -@litchar{\\]} delimiters --- resulting in @tt{script} elements with -@tt{type=math/tex}.} +@litchar{\\]} delimiters --- resulting in eqivalent markup in the output.} ]} diff --git a/markdown/parse.rkt b/markdown/parse.rkt index 887433a..be93d78 100644 --- a/markdown/parse.rkt +++ b/markdown/parse.rkt @@ -637,14 +637,12 @@ (define $math-jax-inline (try (pdo (string "\\\\(") (xs <- (many1Till $anyChar (try (string "\\\\)")))) - (return `(script ([type "math/tex"]) - ,(list->string xs)))))) + (return (string-append "\\(" (list->string xs) "\\)"))))) (define $math-jax-display (try (pdo (string "\\\\[") (xs <- (many1Till $anyChar (try (string "\\\\]")))) - (return `(script ([type "math/tex; mode=display"]) - ,(list->string xs)))))) + (return (string-append "\\[" (list->string xs) "\\]"))))) (define $math-jax ( $math-jax-inline diff --git a/markdown/test.rkt b/markdown/test.rkt index 295737f..adeb0ab 100644 --- a/markdown/test.rkt +++ b/markdown/test.rkt @@ -930,11 +930,9 @@ (!HTML-COMMENT () " more"))))) ;; https://github.com/greghendershott/markdown/issues/52 (check-md "\\\\(ax^2 + bx + c = 0\\\\)" - '((p () (script ((type "math/tex")) - "ax^2 + bx + c = 0")))) + '((p () "\\(ax^2 + bx + c = 0\\)"))) (check-md "\\\\[ax^2 + bx + c = 0\\\\]" - '((p () (script ((type "math/tex; mode=display")) - "ax^2 + bx + c = 0")))) + '((p () "\\[ax^2 + bx + c = 0\\]"))) ;; but single \ still escapes as usual and the contents are still ;; parsed as markdown: (check-md "\\(some *italic* text\\)"