Skip to content

Commit

Permalink
Simplified MathJax
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tfeb committed Jun 3, 2020
1 parent 344ce8d commit 8afdc71
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions markdown/markdown.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -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.}

]}

Expand Down
6 changes: 2 additions & 4 deletions markdown/parse.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
(<or> $math-jax-inline
Expand Down
6 changes: 2 additions & 4 deletions markdown/test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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\\)"
Expand Down

0 comments on commit 8afdc71

Please sign in to comment.