Use version-case to enable tex2svg on Racket 6.12 and above (previous versions lack xexpr-property
).
Will add the dependency on version-case in `info.rkt` as a separate commit, since you can't make code suggestions for lines which are too far from the diff, see https://github.com/isaacs/github/issues/284)
This commit is contained in:
parent
cb0c2b623a
commit
52423aca0d
87
dollar.rkt
87
dollar.rkt
|
@ -10,6 +10,7 @@
|
||||||
"katex-convert-unicode.rkt"
|
"katex-convert-unicode.rkt"
|
||||||
"mathjax-convert-unicode.rkt"
|
"mathjax-convert-unicode.rkt"
|
||||||
racket/list
|
racket/list
|
||||||
|
version-case
|
||||||
(only-in xml cdata)
|
(only-in xml cdata)
|
||||||
(only-in racket/match match)
|
(only-in racket/match match)
|
||||||
(only-in racket/system process)
|
(only-in racket/system process)
|
||||||
|
@ -301,40 +302,42 @@ EOTEX
|
||||||
(elem #:style math-inline-style-katex
|
(elem #:style math-inline-style-katex
|
||||||
(map (λ (s) (katex-convert-unicode s #t)) (flatten strs))))
|
(map (λ (s) (katex-convert-unicode s #t)) (flatten strs))))
|
||||||
|
|
||||||
(define current-tex2svg-path (make-parameter #f))
|
(version-case
|
||||||
|
[(version>= (version) "6.11.0.900"]
|
||||||
|
(define current-tex2svg-path (make-parameter #f))
|
||||||
|
|
||||||
(define (find-tex2svg)
|
(define (find-tex2svg)
|
||||||
(define paths
|
(define paths
|
||||||
(list
|
(list
|
||||||
"./node_modules/.bin/"
|
"./node_modules/.bin/"
|
||||||
"/usr/local/lib/node_modules/mathjax-node-cli/bin/"
|
"/usr/local/lib/node_modules/mathjax-node-cli/bin/"
|
||||||
"/usr/lib/node_modules/mathjax-node-cli/bin/"
|
"/usr/lib/node_modules/mathjax-node-cli/bin/"
|
||||||
"/usr/local/bin/"
|
"/usr/local/bin/"
|
||||||
"/usr/local/sbin/"
|
"/usr/local/sbin/"
|
||||||
"/usr/bin/"
|
"/usr/bin/"
|
||||||
"/usr/sbin/"))
|
"/usr/sbin/"))
|
||||||
(for/or ([path paths])
|
(for/or ([path paths])
|
||||||
(file-exists? (format "~a/tex2svg" path))))
|
(file-exists? (format "~a/tex2svg" path))))
|
||||||
|
|
||||||
(define tex2svg
|
(define tex2svg
|
||||||
(let ([tex2svg-path (find-tex2svg)])
|
(let ([tex2svg-path (find-tex2svg)])
|
||||||
(lambda (#:inline [inline #f] strs)
|
(lambda (#:inline [inline #f] strs)
|
||||||
(if (or (current-tex2svg-path) tex2svg-path)
|
(if (or (current-tex2svg-path) tex2svg-path)
|
||||||
(match (process (format
|
(match (process (format
|
||||||
"tex2svg ~a'~a'"
|
"tex2svg ~a'~a'"
|
||||||
(if inline "--inline " "")
|
(if inline "--inline " "")
|
||||||
(apply string-append strs)))
|
(apply string-append strs)))
|
||||||
[`(,stdout . ,_)
|
[`(,stdout . ,_)
|
||||||
(port->string stdout)])
|
(port->string stdout)])
|
||||||
(error 'tex2svg "Cannot find tex2svg in path or common places; set path manually with current-tex2svg-path.")))))
|
(error 'tex2svg "Cannot find tex2svg in path or common places; set path manually with current-tex2svg-path.")))))
|
||||||
|
|
||||||
|
|
||||||
(define ($-tex2svg strs)
|
(define ($-tex2svg strs)
|
||||||
(elem #:style (style #f
|
(elem #:style (style #f
|
||||||
(list
|
(list
|
||||||
(xexpr-property
|
(xexpr-property
|
||||||
(cdata #f #f (tex2svg #:inline #t (flatten strs)))
|
(cdata #f #f (tex2svg #:inline #t (flatten strs)))
|
||||||
(cdata #f #f ""))))))
|
(cdata #f #f ""))))))])
|
||||||
|
|
||||||
(define ($$-mathjax strs)
|
(define ($$-mathjax strs)
|
||||||
(elem #:style math-display-style-mathjax strs))
|
(elem #:style math-display-style-mathjax strs))
|
||||||
|
@ -343,12 +346,14 @@ EOTEX
|
||||||
(elem #:style math-display-style-katex
|
(elem #:style math-display-style-katex
|
||||||
(map (λ (s) (katex-convert-unicode s #t)) (flatten strs))))
|
(map (λ (s) (katex-convert-unicode s #t)) (flatten strs))))
|
||||||
|
|
||||||
(define ($$-tex2svg strs)
|
(version-case
|
||||||
(elem #:style (style #f
|
[(version>= (version) "6.11.0.900"]
|
||||||
(list
|
(define ($$-tex2svg strs)
|
||||||
(xexpr-property
|
(elem #:style (style #f
|
||||||
(cdata #f #f (tex2svg (flatten strs)))
|
(list
|
||||||
(cdata #f #f ""))))))
|
(xexpr-property
|
||||||
|
(cdata #f #f (tex2svg (flatten strs)))
|
||||||
|
(cdata #f #f ""))))))])
|
||||||
|
|
||||||
(define $-html-handler (make-parameter $-katex))
|
(define $-html-handler (make-parameter $-katex))
|
||||||
(define $$-html-handler (make-parameter $$-katex))
|
(define $$-html-handler (make-parameter $$-katex))
|
||||||
|
@ -363,10 +368,12 @@ EOTEX
|
||||||
($$-html-handler $$-mathjax)
|
($$-html-handler $$-mathjax)
|
||||||
(void))
|
(void))
|
||||||
|
|
||||||
(define (use-tex2svg)
|
(version-case
|
||||||
($-html-handler $-tex2svg)
|
[(version>= (version) "6.11.0.900"]
|
||||||
($$-html-handler $$-tex2svg)
|
(define (use-tex2svg)
|
||||||
(void))
|
($-html-handler $-tex2svg)
|
||||||
|
($$-html-handler $$-tex2svg)
|
||||||
|
(void))])
|
||||||
|
|
||||||
(define ($ . strs)
|
(define ($ . strs)
|
||||||
(let ([$- ($-html-handler)])
|
(let ([$- ($-html-handler)])
|
||||||
|
|
|
@ -172,17 +172,19 @@ details see the documentation of @racket[with-html5].
|
||||||
render the SVG directly to the HTML document.
|
render the SVG directly to the HTML document.
|
||||||
This means no new scripts or stylesheets are added to the document.
|
This means no new scripts or stylesheets are added to the document.
|
||||||
It also has no style, so its style cannot be customized.
|
It also has no style, so its style cannot be customized.
|
||||||
}
|
|
||||||
|
This procedure requires Racket 6.12 or later.}
|
||||||
|
|
||||||
@defproc[($$-tex2svg [math (listof? string?)]) element?]{
|
@defproc[($$-tex2svg [math (listof? string?)]) element?]{
|
||||||
Produces an @racket[element?] which contains the given
|
Produces an @racket[element?] which contains the given
|
||||||
@racket[math] rendered as an HTML SVG literal.
|
@racket[math] rendered as an HTML SVG literal.
|
||||||
It is rendered in @tech{display mode} math using @tt{tex2svg}.
|
It is rendered in @tech{display mode} math using @tt{tex2svg}.
|
||||||
More precisely, the resulting element uses the @racket[xexpr-property] to
|
More precisely, the resulting element uses the @racket[xexpr-property] to
|
||||||
render the SVG directly to the HTML document.
|
render the SVG directly to the HTML document.
|
||||||
This means no new scripts or stylesheets are added to the document.
|
This means no new scripts or stylesheets are added to the document.
|
||||||
It also has no style, so its style cannot be customized.
|
It also has no style, so its style cannot be customized.
|
||||||
}
|
|
||||||
|
This procedure requires Racket 6.12 or later.}
|
||||||
|
|
||||||
@defproc[(use-katex) void?]{
|
@defproc[(use-katex) void?]{
|
||||||
This shorthand calls @racket[($-html-handler $-katex)]
|
This shorthand calls @racket[($-html-handler $-katex)]
|
||||||
|
@ -232,15 +234,18 @@ It also has no style, so its style cannot be customized.
|
||||||
@tt{tex2svg} will only be used when rendering an HTML document, and only if it
|
@tt{tex2svg} will only be used when rendering an HTML document, and only if it
|
||||||
uses @racket[$] or @racket[$$] to render math. It is therefore safe to call
|
uses @racket[$] or @racket[$$] to render math. It is therefore safe to call
|
||||||
this function in libraries to change the default handler.
|
this function in libraries to change the default handler.
|
||||||
}
|
|
||||||
|
This procedure requires Racket 6.12 or later.}
|
||||||
|
|
||||||
@defparam[current-tex2svg-path path path? #:value #f]{
|
@defparam[current-tex2svg-path path path? #:value #f]{
|
||||||
A parameter whose value is the path to the @tt{tex2svg} binary.
|
A parameter whose value is the path to the @tt{tex2svg} binary.
|
||||||
This binary is used to transform math code into HTML when using the @tt{tex2svg}
|
This binary is used to transform math code into HTML when using the @tt{tex2svg}
|
||||||
backend.
|
backend.
|
||||||
The functions @racket[$-tex2svg] and @racket[$$-tex2svg] use this parameter only
|
|
||||||
when rendering the document as HTML.
|
The functions @racket[$-tex2svg] and @racket[$$-tex2svg] use this parameter only
|
||||||
}
|
when rendering the document as HTML.
|
||||||
|
|
||||||
|
This parameter requires Racket 6.12 or later.}
|
||||||
|
|
||||||
|
|
||||||
@;@$${\sum_{i=0}ⁿ xᵢ³}
|
@;@$${\sum_{i=0}ⁿ xᵢ³}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user