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"
|
||||
"mathjax-convert-unicode.rkt"
|
||||
racket/list
|
||||
version-case
|
||||
(only-in xml cdata)
|
||||
(only-in racket/match match)
|
||||
(only-in racket/system process)
|
||||
|
@ -301,40 +302,42 @@ EOTEX
|
|||
(elem #:style math-inline-style-katex
|
||||
(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 paths
|
||||
(list
|
||||
"./node_modules/.bin/"
|
||||
"/usr/local/lib/node_modules/mathjax-node-cli/bin/"
|
||||
"/usr/lib/node_modules/mathjax-node-cli/bin/"
|
||||
"/usr/local/bin/"
|
||||
"/usr/local/sbin/"
|
||||
"/usr/bin/"
|
||||
"/usr/sbin/"))
|
||||
(for/or ([path paths])
|
||||
(file-exists? (format "~a/tex2svg" path))))
|
||||
(define (find-tex2svg)
|
||||
(define paths
|
||||
(list
|
||||
"./node_modules/.bin/"
|
||||
"/usr/local/lib/node_modules/mathjax-node-cli/bin/"
|
||||
"/usr/lib/node_modules/mathjax-node-cli/bin/"
|
||||
"/usr/local/bin/"
|
||||
"/usr/local/sbin/"
|
||||
"/usr/bin/"
|
||||
"/usr/sbin/"))
|
||||
(for/or ([path paths])
|
||||
(file-exists? (format "~a/tex2svg" path))))
|
||||
|
||||
(define tex2svg
|
||||
(let ([tex2svg-path (find-tex2svg)])
|
||||
(lambda (#:inline [inline #f] strs)
|
||||
(if (or (current-tex2svg-path) tex2svg-path)
|
||||
(match (process (format
|
||||
"tex2svg ~a'~a'"
|
||||
(if inline "--inline " "")
|
||||
(apply string-append strs)))
|
||||
[`(,stdout . ,_)
|
||||
(port->string stdout)])
|
||||
(error 'tex2svg "Cannot find tex2svg in path or common places; set path manually with current-tex2svg-path.")))))
|
||||
(define tex2svg
|
||||
(let ([tex2svg-path (find-tex2svg)])
|
||||
(lambda (#:inline [inline #f] strs)
|
||||
(if (or (current-tex2svg-path) tex2svg-path)
|
||||
(match (process (format
|
||||
"tex2svg ~a'~a'"
|
||||
(if inline "--inline " "")
|
||||
(apply string-append strs)))
|
||||
[`(,stdout . ,_)
|
||||
(port->string stdout)])
|
||||
(error 'tex2svg "Cannot find tex2svg in path or common places; set path manually with current-tex2svg-path.")))))
|
||||
|
||||
|
||||
(define ($-tex2svg strs)
|
||||
(elem #:style (style #f
|
||||
(list
|
||||
(xexpr-property
|
||||
(cdata #f #f (tex2svg #:inline #t (flatten strs)))
|
||||
(cdata #f #f ""))))))
|
||||
(define ($-tex2svg strs)
|
||||
(elem #:style (style #f
|
||||
(list
|
||||
(xexpr-property
|
||||
(cdata #f #f (tex2svg #:inline #t (flatten strs)))
|
||||
(cdata #f #f ""))))))])
|
||||
|
||||
(define ($$-mathjax strs)
|
||||
(elem #:style math-display-style-mathjax strs))
|
||||
|
@ -343,12 +346,14 @@ EOTEX
|
|||
(elem #:style math-display-style-katex
|
||||
(map (λ (s) (katex-convert-unicode s #t)) (flatten strs))))
|
||||
|
||||
(define ($$-tex2svg strs)
|
||||
(elem #:style (style #f
|
||||
(list
|
||||
(xexpr-property
|
||||
(cdata #f #f (tex2svg (flatten strs)))
|
||||
(cdata #f #f ""))))))
|
||||
(version-case
|
||||
[(version>= (version) "6.11.0.900"]
|
||||
(define ($$-tex2svg strs)
|
||||
(elem #:style (style #f
|
||||
(list
|
||||
(xexpr-property
|
||||
(cdata #f #f (tex2svg (flatten strs)))
|
||||
(cdata #f #f ""))))))])
|
||||
|
||||
(define $-html-handler (make-parameter $-katex))
|
||||
(define $$-html-handler (make-parameter $$-katex))
|
||||
|
@ -363,10 +368,12 @@ EOTEX
|
|||
($$-html-handler $$-mathjax)
|
||||
(void))
|
||||
|
||||
(define (use-tex2svg)
|
||||
($-html-handler $-tex2svg)
|
||||
($$-html-handler $$-tex2svg)
|
||||
(void))
|
||||
(version-case
|
||||
[(version>= (version) "6.11.0.900"]
|
||||
(define (use-tex2svg)
|
||||
($-html-handler $-tex2svg)
|
||||
($$-html-handler $$-tex2svg)
|
||||
(void))])
|
||||
|
||||
(define ($ . strs)
|
||||
(let ([$- ($-html-handler)])
|
||||
|
|
|
@ -172,17 +172,19 @@ details see the documentation of @racket[with-html5].
|
|||
render the SVG directly to the HTML document.
|
||||
This means no new scripts or stylesheets are added to the document.
|
||||
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?]{
|
||||
Produces an @racket[element?] which contains the given
|
||||
@racket[math] rendered as an HTML SVG literal.
|
||||
It is rendered in @tech{display mode} math using @tt{tex2svg}.
|
||||
More precisely, the resulting element uses the @racket[xexpr-property] to
|
||||
render the SVG directly to the HTML document.
|
||||
This means no new scripts or stylesheets are added to the document.
|
||||
It also has no style, so its style cannot be customized.
|
||||
}
|
||||
Produces an @racket[element?] which contains the given
|
||||
@racket[math] rendered as an HTML SVG literal.
|
||||
It is rendered in @tech{display mode} math using @tt{tex2svg}.
|
||||
More precisely, the resulting element uses the @racket[xexpr-property] to
|
||||
render the SVG directly to the HTML document.
|
||||
This means no new scripts or stylesheets are added to the document.
|
||||
It also has no style, so its style cannot be customized.
|
||||
|
||||
This procedure requires Racket 6.12 or later.}
|
||||
|
||||
@defproc[(use-katex) void?]{
|
||||
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
|
||||
uses @racket[$] or @racket[$$] to render math. It is therefore safe to call
|
||||
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]{
|
||||
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}
|
||||
backend.
|
||||
The functions @racket[$-tex2svg] and @racket[$$-tex2svg] use this parameter only
|
||||
when rendering the document as HTML.
|
||||
}
|
||||
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}
|
||||
backend.
|
||||
|
||||
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ᵢ³}
|
||||
|
|
Loading…
Reference in New Issue
Block a user