suzanne.soy
2021-3-27 16:24:32

(define-runtime-path var dir) only tells racket that we’ll need a the given “dir” which is relative to the source file (so that’s just a pointer to the directory in scribble-math’s source). Then we have (install-resource katex-dir) which asks scribble to copy the contents of dir to the output directory. So changing (define-runtime-path …) will only change the source of the copy, but scribble will still copy the result every time it is executed.

I’m not fond of running (make-directory …) like this. First, the katex-holder name is your preferred name, but other people might have a different folder architecture. Second, there are many “current directory” (since ther’s a relative path ../katex-holder, it needs to be relative to some “current” or “base” directory). There’s the current directory at macro-expansion time, the current directory at run-time, the directory containing the dollar.rkt source, the directory containing your file.scrbl source, the destination directory that scribble uses.

I’m not sure there’s an easy way to know the scribble output directory; furthermore if the user specifies scribble --dest dest/document1 source.scrbl, they don’t expect random files to be created outside of that directory.

Fortunately, scribble already has an option for this:

mkdir dest/common scribble --dest dest/document1/ --dest-base ../common/ --html scribblings/scribble-math.scrbl The mkdir dest/common is a scribble bug (it fails to create the directory on its own), I suggest you report that bug :slightly_smiling_face:

Unfortunately, the generated HTML doesn’t contain a <base href="../common/" /> tag. The only way I could get this to work was to add <base href='../common/' /> to html5-prefix.html, which generates incorrect HTML (the <base …> should be inside the <head>…</head>, not before it), but works.


suzanne.soy
2021-3-27 16:25:07

I’ve asked about that here, let’s see if someone else has a solution.


suzanne.soy
2021-3-27 17:12:23

All right, here’s a temporary fix until someone figures out how to use scribble’s —dest-base correctly: #lang scribble/manual @require[scribble-math] @(define (with-base doc-style) (local-require scribble/core scribble/html-properties) (style (style-name doc-style) (append (list (js-addition (string->bytes/utf-8 "document.write('<base href=\"../common/\" />');"))) ;; re-insert the part of <head> which is above the <base>. This is a quick temporary fix, the <base> should be added at the top of the <head>. (list (js-addition (string->bytes/utf-8 "document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"scribble.css\" title=\"default\"/>');")) (js-addition (string->bytes/utf-8 "document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"racket.css\" title=\"default\"/>');")) (js-addition (string->bytes/utf-8 "document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"manual-style.css\" title=\"default\"/>');")) (js-addition (string->bytes/utf-8 "document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"manual-racket.css\" title=\"default\"/>');")) (js-addition (string->bytes/utf-8 "document.write('<scr'+'ipt type=\"text/javascript\" src=\"scribble-common.js\"></scr'+'ipt>');"))) (style-properties doc-style)))) @title[#:style (with-base (with-html5 manual-doc-style))]{Document 1} @author[@author+email["Suzanne Soy" "racket@suzanne.soy"]] @racket[($-katex "x^2")] renders as @$-katex{x^2}. Compile with: mkdir -p dest/common/ scribble --dest dest/document1/ --dest-base ../common/ --html the-file.scrbl


suzanne.soy
2021-3-27 21:27:11

I also pushed a version with two parameters (use-external-mathjax (or/c #f string?)) and (use-external-katex (or/c #f (list/c string? string?))), you can use those to point to a pre-copied KaTeX folder. For KaTex, do (use-external-katex (list "path/to/katex.min.js" "path/to/katex.min.css"))