diff --git a/Makefile.template b/Makefile.template index c9df072..d4356dd 100644 --- a/Makefile.template +++ b/Makefile.template @@ -17,6 +17,8 @@ bib = # define index if an index is to be generated # index=yes +# override katex variables here if desired + include $(STEXLIB)/Mf-stex # define or override suffixes here diff --git a/Mf-stex b/Mf-stex index 09ec6f3..0ed795d 100644 --- a/Mf-stex +++ b/Mf-stex @@ -28,6 +28,30 @@ else fixbibtex = $(STEXLIB)/$m/fixbibtex endif +ifeq ($(origin KATEX), undefined) +KATEX:=$(if $(shell command -v katex),katex,) +endif +ifneq ($(strip $(KATEX)),) + ifeq ($(strip $(KATEX_CSS)),) + # try to infer KATEX_CSS + katexrealpath:=$(realpath $(shell command -v $(KATEX))) + katexrealdir:=$(dir $(katexrealpath)) + ifeq ($(katexrealpath),) + # can't infer; complain below + else ifneq ($(realpath $(katexrealdir)/dist/katex.css),) + # NPM installation layout (also release tarballs) + KATEX_CSS=$(katexrealdir)/dist/katex.css + else ifneq ($(realpath $(katexrealdir)/katex.css),) + # Debian installation layout + KATEX_CSS=$(katexrealdir)/katex.css + endif + ifeq ($(strip $(KATEX_CSS)),) + $(error cannot find KATEX_CSS for KATEX=$(KATEX)) + endif + endif +endif +export KATEX KATEX_FLAGS + mathdir=math/$(x) mathfiles=$(mathdir)/mathfiles @@ -104,35 +128,62 @@ $(x).firstrun: $(texsrc) all.tex: $(texsrc) +ifeq ($(strip $(KATEX)),) $(x).html: $(x).mathrun +else +$(x).hfourthrun: $(x).mathrun $(x).katex-css-link + $(Hprep) --mathdir $(mathdir) --use-katex --katex-finished --katex-css-link-file $(x).katex-css-link $(x) + chmod 444 *.html + touch $(x).hfourthrun + +# a project may supply one with content to override the default +$(x).katex-css-link: + touch $(x).katex-css-link + +ifeq ($(strip $(KATEX_CSS)),no) +$(x).html: $(x).hfourthrun +else +$(x).html: $(x).hfourthrun katex + +katex: + mkdir -p katex + cp $(KATEX_CSS) katex/katex.css + (cd katex; (cd $(dir $(KATEX_CSS)); tar -cf - --dereference fonts) | tar -xpf -) + chmod u+w katex/katex.css katex/fonts +endif +endif $(x).mathrun: gifs $(mathfiles) @(cd $(mathdir); make) touch $(x).mathrun gifs: - (cd $(STEXLIB); tar -cf - gifs) | tar -xpf - + (cd $(STEXLIB); tar -cf - --dereference gifs) | tar -xpf - + chmod u+w gifs math: - (cd $(STEXLIB); tar -cf - math) | tar -xpf - + (cd $(STEXLIB); tar -cf - --dereference math) | tar -xpf - + chmod u+w math $(mathfiles): $(x).hthirdrun $(figps) echo -n gifs= > $(mathfiles) (cd $(mathdir); echo *.tex | sed -e "s/\.tex/.gif/g") >> $(mathfiles) + echo -n htmls= >> $(mathfiles) + (cd $(mathdir); echo *.katex | sed -e "s/\.katex/.html/g") >> $(mathfiles) $(x).hthirdrun: $(x).hsecondrun - $(Hprep) --mathdir $(mathdir) $(x) + $(Hprep) --mathdir $(mathdir) $(if $(strip $(KATEX)),--use-katex,) $(x) chmod 444 *.html touch $(x).hthirdrun $(x).hsecondrun: $(x).hfirstrun - $(Hprep) --mathdir $(mathdir) $(x) + $(Hprep) --mathdir $(mathdir) $(if $(strip $(KATEX)),--use-katex,) $(x) chmod 444 *.html touch $(x).hsecondrun $(x).hfirstrun: math $(x).thirdrun - (if [ ! -e $(mathdir) ] ; then mkdir -p -m u=rwx,g=srx,o=rx $(mathdir); ln -s ../Makefile ../mathmacros $(mathdir); fi) - $(Hprep) --mathdir $(mathdir) $(x) + (if [ ! -e $(mathdir) ] ; then mkdir -p -m u=rwx,g=srx,o=rx $(mathdir); ln -s ../Makefile ../mathmacros ../katexmacros $(mathdir); fi) + $(Hprep) --mathdir $(mathdir) $(if $(strip $(KATEX)),--use-katex,) $(x) touch $(x).hfirstrun spell: $(spellobj) @@ -143,7 +194,7 @@ $(x).spell: $(x).bbl $(x).tex clean: $(x).clean -/bin/rm -f *.log *.dvi *.aux *.out *.toc *.tmp *.idx *.ilg *.ind *.blg *.bbl *.rfm *.sfm *.firstrun *.secondrun *.thirdrun - -/bin/rm -f *.haux *.htoc *.hidx *.hfirstrun *.hsecondrun *.hthirdrun *.mathrun + -/bin/rm -f *.haux *.htoc *.hidx *.hfirstrun *.hsecondrun *.hthirdrun *.mathrun *.hfourthrun -/bin/rm -f *.tex reallyclean: clean $(x).reallyclean diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 0000000..2b1858a --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1,11 @@ +gifs/ +math/ +*.tex +*.log +*[.h]aux +*[.h]toc +*[.h]firstrun +*[.h]secondrun +*[.h]thirdrun +*.hfourthrun +*.mathrun diff --git a/doc/Makefile b/doc/Makefile index e2ccc0f..e5b8305 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -17,6 +17,9 @@ bib = # define index if an index is to be generated # index=yes +# override katex variables here if desired +KATEX_CSS=no # see comment in stex.katex-css-link + include $(STEXLIB)/Mf-stex # define or override suffixes here diff --git a/doc/stex.css b/doc/stex.css index 8950ff0..702c343 100644 --- a/doc/stex.css +++ b/doc/stex.css @@ -14,6 +14,9 @@ a.image:link, a.image:active, a.image:visited, a.image:hover { background: #FFFFFF; } +.schemedisplay { line-height: 1.0625; } +.schemedisplay .katex { font-size: 1em; } + ul.tocchapter { list-style: none; } ul.tocsection { list-style: circle; color: #923a3a } diff --git a/doc/stex.html b/doc/stex.html index 25a4a70..704cec1 100644 --- a/doc/stex.html +++ b/doc/stex.html @@ -1,10 +1,32 @@ - - + + +
-An stex file is really just a latex file extended with a handful of +An stex file is really just a file extended with a handful of commands for including Scheme code (or pretty much any other kind of code, as long as you don't plan to use the Scheme-specific transcript support) in a document, plus a couple of additional features rather arbitrarily thrown in.
-The subset of latex-formatted files html-prep is capable of +The subset of -formatted files html-prep is capable of handling is rather small but has nevertheless been useful for our purposes, which include producing html versions of a couple of books -(The Scheme Programming Language, Editions 2-4 and the Chez Scheme -User's Guides for Versions 6-9), the scheme.com web site, class websites, +(The Scheme Programming Language, Editions 2–4 and the Chez Scheme +User's Guides for Versions 6–10), the scheme.com web site, class websites, class assignments, and various other documents.
@@ -134,6 +160,8 @@
-
make Scheme=schemepath +
make Scheme=schemepath
where schemepath is the path to the scheme executable.
@@ -156,7 +184,7 @@
-
sudo make install Scheme=schemepath LIB=libdir +
sudo make install Scheme=schemepath LIB=libdir
where schemepath is as described above, and libdir is the directory where the stex library directory should be installed. If libdir is writable by the current user, then sudo @@ -167,7 +195,7 @@
-
sudo make install PREFIX=prefixdir +
sudo make install PREFIX=prefixdir
where prefixdir specifies in one shot the tree under which the Scheme executable is installed and under which the stex library should be installed. @@ -175,7 +203,7 @@
-
sudo make install Scheme=prefixdir/bin/scheme LIB=prefixdir/lib/stexversion +
sudo make install Scheme=prefixdir/bin/scheme LIB=prefixdir/lib/stexversion
where version is the stex version number.
@@ -298,7 +326,7 @@
-@@ -439,7 +467,18 @@(define fact
+(define fact
(lambda (x)
@@ -314,7 +342,7 @@4.2. Code displays
Within a Scheme display, ;=> is converted into a double right arrow -(
), ;-> into a single right arrow (
), and +(), ;-> into a single right arrow (), and ;== into a phantom of the same size. This is useful for showing what a piece of code translates or evaluates to, e.g.: @@ -350,14 +378,14 @@
4.2. Code displays
A let expression expands into a call to a lambda expression, e.g.: -(let ([a 17])
((lambda (a) (+ a a))
+(let ([a 17]) ((lambda (a) (+ a a))
- (+ a a))17) + (+ a a)) 17)
A let expression first evaluates the right-hand-side expression, then evaluates the body in an environment that binds the left-hand-side variable to the resulting value, e.g.: -
(let ([a 17])
17
+(let ([a 17]) 17
(+ a a))
-(sqrt x)
![]()
. +
(sqrt x) .
@@ -574,7 +613,7 @@
-> (define f
+> (define f
(lambda (x) ; indentation and comments are
@@ -676,7 +715,7 @@5.1. Automatic transcript generation
-> #e4.5
+> #e4.5
9/2
@@ -786,7 +825,7 @@5.1. Automatic transcript generation
-> (begin (display "> \n") (exit))
+> (begin (display "> \n") (exit))
>
@@ -817,7 +856,7 @@5.1. Automatic transcript generation
-> (waiter-prompt-string "antelope? ")
+> (waiter-prompt-string "antelope? ")
antelope? "no thanks"
@@ -883,7 +922,7 @@5.2. Loading initialization code
The compute-length procedure behaves as follows: -
> (compute-length '())
+> (compute-length '())
0
@@ -963,22 +1002,97 @@6. html-prep support for the tabular envir
-++
-y = f(x) without loss of generality -z whee this is fun? - - -
- 1 2 - 3 4 - -a b c d -12345 z (define x "foo") -
+y = f(x) without loss of generality +z whee this is fun? + + +
+ 1 2 + 3 4 + +a b c d +12345 z (define x "foo") + 7. Math in HTML
+ + + + ++A few very simple uses of 's math mode are converted to HTML directly by +html-prep. For typesetting non-trivial math, there are two strategies +available: + +
+
+
+- Originally, stex used to render math to GIF images. +
- Optionally, stex can use , which generates MathML and/or HTML. +
+ +
+Using makes the rendered math accessible to assistive technologies, +CSS, and other browser features. It also tends to look better than math in +GIFs. However, a few features that stex supports when rendering to GIFs, +notably including \epsfbox{} and the +eqnarray* environment, are not currently supported when rendering with +. + +
+By default, stex will use if the "katex" command is found; otherwise, +it will automatically fall back to generating GIFs. To prevent stex from using + even if it is available, use make KATEX= or define +KATEX as empty in your makefile before including Mf-stex. The same +mechanisms can be used to supply a non-default "katex" command or even to +require that be present, e.g. by writing: + +
+
++ ++KATEX:=$(if $(shell command -v katex),katex,$(error katex not found)) ++ ++The variable KATEX_FLAGS may be used to supply additional options for +. + +
+The output of requires supporting CSS and font files. (Notably, it does +not require JavaScript. It is also possible to supply non-default options to +create output that can work without CSS and fonts by relying solely on the +native support for MathML in recent browsers and operating systems.) By +default, stex will attempt to find these files relative to the "katex" +command, and it should be able to handle the installation layouts used by both +Node.js and Debian. If the files cannot be found automatically, you will need +to define KATEX_CSS, either at the command line or in your makefile +(before including Mf-stex): likely values include +"./node_modules/katex/dist/katex.css" and +"/usr/share/javascript/katex/katex.css". + +
+By default, stex copies the needed CSS and font files into a directory named +"katex" alongside the generated HTML files: when using , you need to +install this directory or upload it to your web server. + +
+As a special case, defining KATEX_CSS=no instructs stex not to copy +these files. If you use this option, you may also want to override the default +HTML link element used to load the CSS by creating a non-empty file +with the base name of your document and the extension ".katex-css-link": for +an example, see the "stex.katex-css-link" file used for this document. +
- © 1998-2016 R. Kent Dybvig and Oscar Waddell + © 1998–2016 R. Kent Dybvig and Oscar Waddell